This article mainly introduces the PHP statistical array of elements of the method of the relevant data, the need for friends can refer to the following
COUNT (): counts the number of elements in the array;
sizeof (): and Count () have the same purpose, both functions 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;
Such as:
$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
Send a Netizen's train of thought, also very good
$arr = Array ( ' 1011,1003,1008,1001,1000,1004,1012 ', ' 1009 ', ' 1011,1003,1111 ' ); $result = array (); foreach ($arr as $str) { $str _arr = Explode (', ', $str); foreach ($str _arr as $v) { $result [$v] = Isset ($result [$v])? $result [$v]: 0; $result [$v] = $result [$v] + 1; }} Print_r ($result);