Re: counting array elements
| From: | Jason Wong | Date: | Mon, 24 Feb 2003 09:17:38 +0000 |
| Subject: | Re: counting array elements | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-136862@lists.php.net to get a copy of this message | ||
On Monday 24 February 2003 16:12, Kevin Waterson wrote:
> I wish to fine the most occurringest value in an array. eg:
>
> $arr = array('dog', 'cat', 'dog', 'zebra',
> 'cat', 'dog', 'dog', 'dog');
>
> if I use array_count_values it gives "dog => 5"
> I would like to get 'dog' and '5' into a $variable.
$arr = array('cat', 'dog', 'cat', 'dog', 'zebra',
'cat', 'dog', 'dog', 'dog');
$doo = array_count_values($arr);
arsort($doo);
$dah = each ($doo);
$creature = $dah[0];
$count = $dah[1];
print "$creature appeared $count times!";
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
"You shouldn't make my toaster angry."
-- Household security explained in "Johnny Quest"
*/