Re: Array difficulty

From: Date: Tue, 31 Jul 2007 13:48:29 +0000
Subject: Re: Array difficulty
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-259903@lists.php.net to get a copy of this message
I tried that earlier, but the problem is: count( $chance ) - 1 ); returns an integer, so I would be asking for something like $chance[1] or $chance[0], neither of which exist in the array. Keep in mind $chance only has keys with string names: The array looks like this: $chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46); The values assigned to each key are randomly generated. Regards, Carlton Whitehead ----- Original Message ----- From: "Chris Boget" <chris.boget@wild.net> To: "Carlton Whitehead" <carlton.whitehead@cebesius.com>, php-general@lists.php.net Sent: Tuesday, July 31, 2007 9:43:00 AM (GMT-0500) America/New_York Subject: RE: [PHP] Array difficulty > 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? Couldn't you just do arsort($chance); $lastItem = chance[( count( $chance ) - 1 )]; ? Why iterate through the array when all you need is the last value? thnx, Chris

« previous php.general (#259903) next »