How to represent the total number of loop arrays in php-php Tutorial

Source: Internet
Author: User
In php, the prerequisite for expressing the total number of loop arrays is for loop.
For example, there are N times in this loop.
So how can we calculate the N value?
Of course, many people will say that $ num = 0; $ num ++;
This is acceptable, but not suitable for my needs,
My requirement is to display this number directly in the for loop.
For ($ I = 0; $ I <9; $ I ++ ){
Total number of cycles * $ I
}
In this case, you can use $ num = 0; $ num ++ in it,


Reply to discussion (solution)

Isn't your cycle number 9?

$ I = 0; $ I <9 can calculate the number of cycles
But I don't think I will ask such a simple question...
Is it estimated that the for loop is an array of unknown stop points?
Either loop twice. for the first time, only the stop point is determined, or the data structure is modified to facilitate management.
The possibility of unreasonable data structures is higher.

The end value of the for loop must be specified.
Isn't this N?
For your
For ($ I = 0; $ I <9; $ I ++ ){
Total number of cycles * $ I
}
Isn't the total number of cycles 9?

If the final value is uncertain, you have to preview it first.

This is generally the case.

For ($ I = 0; $ I
Count ($ arr) * $ I
}

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.