Complete the code to print numbers 1 to 3 using a for loop.
<?php for ($i = 1; $i [1] 3; $i++) { echo $i . " "; } ?>
The for loop should run while $i is less than or equal to 3 to print numbers 1, 2, and 3. Using <= will loop correctly.
Complete the code to print a 3x3 grid of stars using nested loops.
<?php for ($i = 1; $i <= 3; $i++) { for ($j = 1; $j [1] 3; $j++) { echo "* "; } echo "<br>"; } ?>
The inner loop should run while $j is less than or equal to 3 to print 3 stars per line.
Fix the error in the nested loop to print numbers 1 to 3 in each row.
<?php for ($i = 1; $i <= 3; $i++) { for ($j = 1; $j [1] 3; $j++) { echo $j . " "; } echo "<br>"; } ?>
The inner loop must run while $j is less than or equal to 3 to print numbers 1, 2, and 3.
Fill both blanks to create a nested loop that prints a 4x4 grid of numbers.
<?php for ($i = 1; $i [1] 4; $i++) { for ($j = 1; $j [2] 4; $j++) { echo $j . " "; } echo "<br>"; } ?>
Both loops should run while their counters are less than or equal to 4 to print numbers 1 to 4 in each row and 4 rows total.
Fill all three blanks to create a nested loop that prints a multiplication table from 1 to 3.
<?php for ($i = 1; $i [1] 3; $i++) { for ($j = 1; $j [2] 3; $j++) { echo $i [3] $j . " "; } echo "<br>"; } ?>
Both loops run while their counters are less than or equal to 3. The multiplication operator (*) is used to print the product of $i and $j.