How to obtain the value in a loop statement

Source: Internet
Author: User
How to obtain the value in a loop statement
for($i = 0; $i <= 2; $i++){  $i;}   echo $i;

In this case, why can't we get the value from the loop? so we can get the last one and change it to this.
for($i = 0; $i <= 2; $i++){    echo $i;} 

In this way, we can get all the values, but some statements don't want to be placed in the loop statements. Is there any way to get the values in the loop statements?


Reply to discussion (solution)

Use a variable (array or character) in the loop statement to save the value of each loop and call it outside the loop.

Not saved. of course, the last one is obtained each time.

This is the logic of your needs.

If the statement is placed outside the loop, this is okay. but how can I use a specific number of loops in the loop? How do you determine which time to use?

This is the logic of your needs.

If the statement is placed outside the loop, this is okay. but how can I use a specific number of loops in the loop? How do you determine which time to use?
I also think there is a logic problem. In fact, I want to get the value of the inner edge of the loop statement outside the loop statement, but I don't have any idea or code. I don't know how to write it.

Use a variable (array or character) in the loop statement to save the value of each loop and call it outside the loop.
This method is feasible, but how can I write the specific code? how can I write the code for the Cainiao to refer?

for($i = 0; $i <= 2; $i++){  $t[] = $i;} echo join(',', $t);


This is the logic of your needs.

If the statement is placed outside the loop, this is okay. but how can I use a specific number of loops in the loop? How do you determine which time to use?
I also think there is a logic problem. In fact, I want to get the value of the inner edge of the loop statement outside the loop statement, but I don't have any idea or code. I don't know how to write it.

Then you should first think about the logic and process. programming is actually to convert the logic into code... you can also say that you can help you sort out the logic in detail.

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.