Definition:
A nested loop means one loop inside another. When there is a lot of data in the table, it is processed accordingly. When the outer loop or statement meets its condition, it also meets the condition of the inner statement or loop. After finishing the inner loop, it also exits the outer loop.
Syntax:
for ($i = 1; $i <= 3; $i++) { // This is Outer loop.
for ($j = 1; $j <= 2; $j++) { // This is Inner loop.
echo "i = $i, j = $j<br>";
}
}
Example:
<?php
for ($i = 1; $i <= 3; $i++) { // This is Outer loop.
for ($j = 1; $j <= 2; $j++) { // This is Inner loop.
echo "first loop <br>";
}
}
?>
Output:
first loop first loop
