Re: [PHP] Array difficulty
- From: rich@xxxxxxxxxxxxx (Richard Davey)
- Date: Tue, 31 Jul 2007 14:42:32 +0100
Hi Carlton,
Tuesday, July 31, 2007, 2:27:46 PM, you wrote:
I have an array like this:
$chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46);
The values for each of the keys are randomly generated. I want to
find the key name of the one which has the highest value. Currently, I'm doing this as follows:
arsort($chance);
foreach ($chance as $type => $value)
{
$result = $type;
break;
}
At this point, $result would be equal to "uppercase". I feel like
this is a really kludgey way to accomplish this. Is there a better way?
Not tested it, but max() should work as the first parameter can be an
array:
http://uk3.php.net/max
Cheers,
Rich
--
Zend Certified Engineer
http://www.corephp.co.uk
"Never trust a computer you can't throw out of a window"
.
- Follow-Ups:
- Re: [PHP] Array difficulty
- From: "Chris Boget"
- Re: [PHP] Array difficulty
- References:
- Array difficulty
- From: Carlton Whitehead
- Array difficulty
- Prev by Date: Re: [PHP] Bizarre array create error
- Next by Date: Re: [PHP] Re: Pirate PHP books online?
- Previous by thread: Array difficulty
- Next by thread: Re: [PHP] Array difficulty
- Index(es):
Relevant Pages
|