How to dynamically generate a multiplication table

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.

Snapshot of the multiplication table generated by PHP

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.

What interesting questions were you asked at interviews? I would love to know.

Thanks for geeking out with me,

Signed By Femy Praseeth

Share it with your people:

Leave a Reply

Your email address will not be published. Required fields are marked *

Endorsed by these folks ...

Femy is an absolute joy to work with. She’s very knowledgeable as a front end developer and takes the time to make sure things are right the first time. Her work is very clean and professional and her attitude is great…all the time! She’ll take the time to help you even if she is already booked. Femy is a great asset to SolutionSet.

Jaime Lutz Project Manager, SolutionSet