Interleaving of PHP Local variables and global variables (one) nesting variables in the For loop

Source: Internet
Author: User
Believe that a lot of students from c++/java/c# and so on, may make such a mistake:

 
 

Outside a large for loop, write a lot of code after, but also a loop, we do not want to throw another I, we in other languages are so dry, but in PHP this way, you will find that the code into a dead loop! What is the reason?

The original for statement is not a function, just a statement form, in PHP, two I are treated as global variables, each run to the end of the loop, I have been re-assigned to 7, of course, will never jump out of the loop.

My solution is to try to separate the self-increment variable names of each for loop, which can greatly avoid this problem. and use foreach as much as possible.

The above describes the PHP local variable and global variable interleaving (a) nested for the variable in the loop, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.