Answers to questions about how to get the values in a loop statement

Source: Internet
Author: User
for ($i = 0; $i <= 2; $i + +) {  $i;}   echo $i;

So why not get the value of getting the loop out of this to get the last one modified into this
for ($i = 0; $i <= 2; $i + +) {    

So that you can get all the values, but some of the statements do not want to put in the loop statement, what is the way to get the value in the loop statement?


Reply to discussion (solution)

In a looping statement, a variable (array or character) is used to hold the value of each loop, which is called outside the loop.

Did not save, of course, every time to get the last one.

Landlord This is the logic of your need to have a problem

The statement is placed outside the loop, which is fine, but how does a statement outside the loop use the value of a particular loop within a loop? How do you decide which one to use?

Landlord This is the logic of your need to have a problem

The statement is placed outside the loop, which is fine, but how does a statement outside the loop use the value of a particular loop within a loop? How do you decide which one to use?
I think there's a problem with logic, actually, I want to get the value of the inner edge of the loop statement outside of the loop statement, but there's no idea or code to write.

In a looping statement, a variable (array or character) is used to hold the value of each loop, which is called outside the loop.
This method is feasible but the specific code to write the master write code to let the novice reference

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


Landlord This is the logic of your need to have a problem

The statement is placed outside the loop, which is fine, but how does a statement outside the loop use the value of a particular loop within a loop? How do you decide which one to use?
I think there's a problem with logic, actually, I want to get the value of the inner edge of the loop statement outside of the loop statement, but there's no idea or code to write.

Then you first think about logic and process, programming is actually to translate logic into code ... We can help you sort out the logic.

  • Related Article

    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.