Introduction: After learning PHP and jquery, the memory of the function is not in place, resulting in a lot of functions do not remember, so in order to promote their own memory, spend a little time every day to write this blog.
Date: 2016-12-21 Location: Taiyuan Weather: Sleet
One. PHP functions
1.array_count_values the number of occurrences of all values in the statistics array
Description
Array Array_count_values ($input)
The Array_count_values () function returns an array that takes the value of the input array as the key name and the number of occurrences of the value in the input array as the key value.
Parameters:
An array of $input statistics
return value:
Returns an associative array that uses the value in the input array as the key name, the number of occurrences in the array as the value.
Error/exception: a warning error ( E_WARNING ) is thrown for each element inside an array that is not a string and an integer type.
$test =[ "One" =>11, "=>11", " =>33" , "=>144" , "=>55", "" "=>55, "=>77", "=>77", "=>99", " ;p rint_r" (Array_count_values ($test));
The result is:
Array ( [One] = 2 [] = 1 [144] = 1 [+] = 2 [all] = 2 [in] + 1)
Related functions:
- COUNT ()-Calculates the number of cells in an array or the number of attributes in an object
- Array_unique ()-Removes duplicate values from the divisor group
- Array_values ()-Returns all values in the array
- Count_chars ()-Returns information about the characters used in the string
If it is a two-dimensional array such as:
$ar 1[] = Array ("Red", "green", "yellow", "blue"); $ar 1[] = Array ("green", "yellow", "brown", "Red", "white", "yellow"); $ar 1[] = Array ("Red", "green", "Brown", "Blue", "Black", "yellow");p Rint_r (Array_count_values ($arr 1));
The result is:
Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154
Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154
Warning: Array_count_values (): Can only Count STRING and INTEGER values! In E:\Appserv\www\test.php on line 154
Array ()
So write one for the multidimensional array:
Remember PHP functions every day, jquery functions and Linux commands (iii)