Re: Array difficulty

From: Date: Tue, 31 Jul 2007 13:58:56 +0000
Subject: Re: Array difficulty
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259906@lists.php.net to get a copy of this message
On 31/07/07, Carlton Whitehead <carlton.whitehead@cebesius.com> wrote: > Hi all, > > 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; > } > Assuming $chance is non-empty. $result = array_search(max($chance), $chance);

« previous php.general (#259906) next »