php code for counting the number of occurrences of the same value in an array (array_count_values), arraycountvalues
php counts the number of occurrences of the same value in an array. You can use php’s own function array_count_values
:
Description
array array_count_values ( array $input )array_count_values() returns an array that uses the value in the input array as the key name and the number of times the value appears in the input array as the value.
array_count_values() example
Copy code The code is as follows:
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values ($array));
?>
The above routine will output:
Copy code The code is as follows:
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
http://www.bkjia.com/PHPjc/945713.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/945713.htmlTechArticlephp code for counting the number of occurrences of the same value in an array (array_count_values), arraycountvalues php counts the number of occurrences of the same value in an array, you can use PHP comes with the function array_count_values: Description...