Category Archives: Array

PHP array_count_values($arr)

array_count_values($arr)
creates a histogram for the values in an array
<?php
$states = array(“MP”,”AP”,”RJ”,”UP”,”MH”,”HM”,”AP”,”RJ”,”MP”,”MH”,”AP”);
$xstates = array_count_values($states);
ksort($xstates);
print_r($xstates);
?>
Result: –
Array
(
[AP] => 3
[HM] => 1
[MH] => 2
[MP] => 2
[RJ] => 2
[UP] => 1
)
Advertisements