In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to iterate the number of array elements in php". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "php how to iterate the number of array elements".
Implementation: 1, define a counter variable, syntax "$len=0;"; 2, loop through the array, syntax "foreach ($arr as $v) {}"; 3, in the body of the loop, count the number with the "$len++;" statement, each cycle, the counter value will be added 1 × 4, the end of the loop, the output counter value can be.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Php loop to calculate the number of array elements
In php, when you mention circular arrays, you think of for and foreach statements.
However, when the for statement loops through the array, you need to know the length of the array, so this article does not apply.
So we need to use the foreach statement to loop through the array.
Realize the idea:
Define a counter variable $len with a value initialized to 0, which is used to count the number of array elements.
Use the foreach statement to loop through the array
In the body of the loop, use the "+" operator to calculate the number, and add 1 to the counter value for each loop.
At the end of the loop, output the value of the counter.
Implementation code:
Is it correct? Let's use the built-in function to verify:
The number of elements in the echo "array is:" .count ($arr)
At this point, I believe you have a deeper understanding of "php how to iterate the number of array elements". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.