Help to make a conclusion numbers.

the function should draw the following result

1 2 3 4
2 4 6 8
3 6 9 12

And I can not so, how to fix it?

function foo3($a,$b){ for($i = 1; $i <= $a; $i++){ for($t = 1; $t <= $b; $t++){ } echo $i; echo $i * 2; echo $i * 3; echo '<br>'; } } 

foo3 (4,3)

    1 answer 1

    • You did not have a closing bracket for the second cycle (it turned out to be an idle cycle).
    • Because you go over the loop with counters for good reason, then they must be multiplied. Otherwise, why all these echo $i; echo $i * 2; echo $i * 3; echo $i; echo $i * 2; echo $i * 3; ??? I personally did not understand.
    • Because If you want to get an "inverted" output, then you need to go over the cycle to the value of $b , and the second to $a .
    • Well, to separate the lines through <br/> only in the first cycle is necessary.

       function foo3($a,$b){ for($i = 1; $i <= $b; $i++){ for($t = 1; $t <= $a; $t++){ echo $i * $t.' '; } echo '<br>'; } } foo3(4,3);