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
)

Tagged: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: