PHP is the best way to print a multiplication table
Basic PHP. I decided to print a list of 10 multiples of 17.5, for example:
17.5 | 35 | 52.5 | 70 | 87.5 | 105 | 122.5 | 140 | 157.5 | 175 |
So, I used this loop first:
<?php
$number = 17.5;
$result = 0;
$i = 0;
while ($i < 10) {
$result += $number;
echo $result.' | ';
$i++; }
Well it works. Then I switched to this, which is pretty short:
$i = 1;
$result = 17.5;
while ($i <= 10) {
echo $result * $i.' | ';
$i++; }
But I'm sure there is a better way. What's the best syntax?
+3
source to share