In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to check how many values an array has in php". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Methods: 1. Create a counter variable, the value is set to 0;2. Loop through the array, syntax "foreach($arr as $v)";3. In the loop body, determine whether the element is a numerical value, if yes, the counter increases by 1, syntax if(is_numeric($v)){$n++;}";4. Loop ends, output the counter.
Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer
How does PHP check how many values an array has?
Php checks how many values an array has and counts the number of numeric elements in the statistical array.
Implementation method:
Create and initialize a counter variable with a value of 0 for counting.
Loop through arrays using foreach
In the loop body, the is_numeric function determines whether the array element is a numeric value; if it is a numeric value, the counter increments by 1.
Cycle ends, output counter can be.
Implementation code:
As you can see, there are five numeric elements in the array.
"php how to check an array has several values" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.