: This article mainly introduces the staggered relationship between local variables and global variables in PHP (1) Nested Variables in the for loop. for more information about PHP tutorials, see. I believe many students from c ++/java/c # may make the following mistakes:
There is a big for loop outside. after a lot of code is written, we need another loop. you don't want to throw another I. We do this in other languages, but after php does this, you will find that the code turns into an endless loop! What is the reason?
Originally, the for statement is not a function, but a statement form. in php, both I are treated as a global variable, and the loop in each run is complete, I has been assigned 7 again, and of course it will never jump out of a loop.
My solution is to try to separate the auto-increment variable names of each for loop, which can greatly avoid this problem. And try to use foreach.
The above introduces the staggered relationship between local variables and global variables in PHP (1) nested for loop variables, including some content, and hope to be helpful to those who are interested in PHP tutorials.