PHP obtains the length of an array or the number of occurrences of a value. This article describes how PHP obtains the length of an array or the number of occurrences of a value () and array_count_value (PHP method for obtaining the array length or the number of occurrences of a value
This article describes how to obtain the length of an array or the number of occurrences of a value in PHP. The example analyzes the usage skills of count () and array_count_value (). For more information, see
This example describes how to obtain the length of an array or the number of occurrences of a value in PHP. Share it with you for your reference. The specific analysis is as follows:
Count (): counts the number of elements in the array;
For example:
?
1 2 |
$ Arr = Array ('0', '1', '2', '3', '4 '); Echo count ($ arr); // output 5 |
Sizeof () and count () have the same purpose. both functions can return the number of array elements. we can get the number of elements in a regular scalar variable. If the array passed to this function is an empty array or an unspecified variable, the number of returned array elements is 0;
Array_count_value () counts the number of times each specific value has exceeded in the array $ array;
For example:
?
1 2 |
$ Array = array ); $ Ac = array_count_value ($ array ); |
An array named $ ac will be created, including:
Keyword value
4 1
5 1
1 3
2 2
3 1
I hope this article will help you with php programming.
This article describes how to obtain the length of an array or the number of occurrences of a value in PHP. The example analyzes the values of count () and array_count_value (...