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";
}
}
Nesta página do site você pode assistir ao vídeo on-line Nested loops in PHP explained duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário PHP Explained 19 Março 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 100 vezes e gostou 2 espectadores. Boa visualização!