I couldn't think of a way of explaining why I would assign variables without confusing you more, so I've included my solution to this task to illustrate the point. You were very close to a solution with your way, so I took that as my starting point.
Basically, you can assign strings to a variable just like you assigned the numbers the $x and $y variables in your loops. You can also keep adding more to that variable by using .= this says the variable equals my current value plus the new stuff I'm adding. When you've finished adding everything to your variable you can then display it using echo, for example echo $variable;
// Start table
echo "<table border=1 width=25>";
// Set top row and first cell which is empty
$multiplierRow = "<tr style='color:red'><td> </td>";
$sumRow = "";
for ($x = 1; $x <= 12; $x++ )
{
$multiplierRow .= "<td>".$x."</td>";
// Start new row
$sumRow .= "<tr>";
// First column, multiplier column
$sumRow .= "<td style='color:red'>".$x."</td>";
for ( $y = 1; $y <= 12; $y++ )
{
// Actual results
$sumRow .= "<td>".$x * $y."</td>";
}
$sumRow .= "</tr>";
}
$multiplierRow .= "</tr>";
// Display top row
echo $multiplierRow;
// Display subsquent rows
echo $sumRow;
// Close table
echo "</table>";
One thing to note is I started your $y loop from 1 otherwise you don't get the times one column.