Nested loops means one loop contains another loop.
There are four ideal loop structure available in PHP and these are while, do while, for, and foreach loop.
Any of these four types of loops can contain each other to form nested loop. There is no limitation of nested number of loops.
Let's explain with an example.
Here we are using for loop.
First for loop called outer for loop contains another for loop called inner for loop.
Outer loop consists of variable i and iterates for 10 times.
Inner loop consists of variable j and iterates for 10 times also.
For one iteration of the outer loop, the inner loop iterates 10 times. So, all together 10 times outer multiplied by 10 times inner iterations, equal to 100, hence the loops are iterating for 100 times.
for ($i = 1; $i lt;= 10; $i++)
{
for ($j = 1; $j lt;= 10; $j++)
{
echo $i . " " . $j . "\n";
}
}
Auf dieser Seite können Sie das Online-Video Nested loops in PHP explained mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer PHP Explained 19 März 2025 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 100 Mal angesehen und es wurde von 2 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!