blogpost: how to dynamically generate a multiplication table using PHP

How to dynamically generate a multiplication table using PHP

Posted on:

I was asked in an initial interview screening to generate a multiplication table using PHP. Here is the prototype of what I came up with, in the interview test.

PHP code to generate the multiplication table inside the HTML

<table>
<?php for($i=0; $i<=12; $i++){
echo "<tr><th>$i</th>";
for($j=1; $j<=12; $j++){
if($i == 0){
echo "<th>$j</th>";
continue;
}
$total = $i * $j;
echo "<td>$total</td>";
}
echo "</tr>";
}
echo "</tr>"; ?>
</table>

I hope you found this article interesting.