Variables that are urgently needed in the PHP loop block are defined outside the loop or inside the loop.

Source: Internet
Author: User
The variables required in the PHP loop block are defined outside the loop or in the loop? For example, does the definition create a variable in each loop? Php: Well, it depends on your needs. this depends on your needs. if you want to use the variables required in the PHP loop block, should they be defined outside the loop or in the loop?
For example, does the definition create a variable in each loop? Php
------ Solution --------------------
Well, let's look at your needs.
------ Solution --------------------
This depends on your requirements. if you want to change the value of a variable, you can use the variable for the next time and put it on the outside. if it is only effective in each loop, it is placed on the inside.




------ Solution --------------------
Can be placed outside, not inside
Can be placed on the outer layer instead of on the internal layer
------ Solution --------------------
If you want to use it multiple times without changing the variable value, we recommend that you put it out. If it is used only in a loop and the value may change, put it in it.
------ Solution --------------------
In my opinion: after using a variable, remember to unset it, so you don't have to worry about it.
------ Solution --------------------
Reference:
Reference: If you want to use it multiple times without changing the variable value, we recommend that you put it out. If it is used only in a loop and the value may change, put it in it.

Each use is a new value.


Agree with the upstairs, not unset. Since the variable values are different, you only need to assign a value to the variable before each use. You don't have to worry about putting it inside or outside.
------ Solution --------------------
The variable will not change during the cycle if it is placed in the external body of the loop as needed; if it is placed in the circulatory body, the variable will change during the cycle
------ Solution --------------------
It is defined outside the loop body. after each use in the loop body, it is initialized to the original state.

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.