PHP for loop : equal or smaller than - works, equal to - creates infinte loop -


this code works

<?php      ($x = 0; $x <= 10; $x++) {         echo "the number is: $x <br>";     }  ?>  

but if instead of " <= " use " = " php gets infinite loop timesout

<?php          ($x = 0; $x = 10; $x++) {             echo "the number is: $x <br>";         }  ?> 

is expected behavior?

yes, you're using assignment operator instead of comparison operator. there's no way loop end.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -