PHP local variables and global variables (1) Nested Variables in the for loop

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.