How PHP Gets the array length or the number of occurrences of a value
This article mainly introduces the method of getting the length of an array or the number of occurrences of a value in PHP, the example analyzes the use of count () and Array_count_value (), the need for friends can refer to the following
This example describes how PHP gets the array length or the number of occurrences of a value. Share to everyone 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 of which can return the number of array elements. You can get the number of elements in a regular scalar variable, if the array passed to the function is an empty array, or is an array of variables that are not set, the number of elements returned is 0;
Array_count_value () counts the number of occurrences of each particular value in the array $array;
For example:
?
1 2 |
$array =array (4,5,1,2,3,1,2,1); $ac =array_count_value ($array); |
An array named $ac is created, which includes:
Keyword value
4 1
5 1
1 3
2 2
3 1
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/956989.html www.bkjia.com true http://www.bkjia.com/PHPjc/956989.html techarticle how PHP gets the length of an array or the number of occurrences of a value this article mainly introduces how PHP gets the array length or the number of occurrences of a value, and the instance analyzes the count () with Array_count_value (...) .