How php checks how many values there are in an array
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!