This paper mainly makes a simple introduction of count. Although it is often used in daily life, we have not yet understood the small details.
Count you don’t know how to use
While we’re at it, kaka gives you a general idea of a use of count that isn’t very common.
This is one of the most common and frequently seen use cases in development.
Use an array directly and return the length of the array.
But if you are given a multidimensional array, such as the figure below, and asked to count this multidimensional array, how do you count it?
At this point, I think most of you are going to loop and define a counter to accumulate.
In fact, the count() function solves this requirement in this section.
The bottom print is “4—-6”
Using the count() function directly on an array gives you the length of the first array.
But the count() function takes a second argument, set to 1, to recursively count the number of elements in the array.
So if you look at the documentation at this point, the count() function itself takes two arguments
The first argument is must hungry, and the selection is array
The second argument defaults to 0 and does not count all elements in the multidimensional array
When the second argument is 1, it recursively evaluates all the elements in the multidimensional array.
Study each technical point carefully, study a technical point thoroughly, no matter what writing or doing can be done with ease.
Sometimes it’s not necessary to memorize everything, but it’s important to know that you can pull it out when you need it.