Is there any difference between the two for loops in php?

the following two for loops perform differently.


for($i = 0,$j = 0;$i < 5 && $j < 5;$iPP,$jPP){
    dump($i . "-" . $j);
}


echo "<hr>";

for($i = 0;$i < 5;$iPP){
    for($j = 0;$j < 5;$jPP){
        dump($i . "*" . $j);
    }
}

result print:

string(3) "0-0"
string(3) "1-1"
string(3) "2-2"
string(3) "3-3"
string(3) "4-4"
-------------------------------------------------------------------------------------------
string(3) "0*0"
string(3) "0*1"
string(3) "0*2"
string(3) "0*3"
string(3) "0*4"
string(3) "1*0"
string(3) "1*1"
string(3) "1*2"
string(3) "1*3"
string(3) "1*4"
string(3) "2*0"
string(3) "2*1"
string(3) "2*2"
string(3) "2*3"
string(3) "2*4"
string(3) "3*0"
string(3) "3*1"
string(3) "3*2"
string(3) "3*3"
string(3) "3*4"
string(3) "4*0"
string(3) "4*1"
string(3) "4*2"
string(3) "4*3"
string(3) "4*4"

replace the & & in the first for loop with | | the printed result is the same. What"s the difference?
this way of writing is usually rarely used, and Baidu can"t find a reason, so I"m here to ask for advice.

Php
May.05,2021

how can it be the same?
one is a single loop
one is a nested loop


difference:

  • one is a single loop and the other is a double loop
  • $iGrainj is increasing at different times

one cycle 5 times, one cycle 25 times, do you say the same


difference?
the difference is that the first cycle is 5 times, and the second cycle is 5 * 5 times

Menu