Re: [PHP] Array difficulty

2007-08-07 Thread Richard Lynch
On Tue, July 31, 2007 8:27 am, Carlton Whitehead 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. Curren

Re: [PHP] Array difficulty

2007-07-31 Thread Robin Vickery
On 31/07/07, Alister Bulman <[EMAIL PROTECTED]> wrote: > On 31/07/07, Carlton Whitehead <[EMAIL PROTECTED]> wrote: > >> Couldn't you just do > >> arsort($chance); > >> $lastItem = chance[( count( $chance ) - 1 )]; > > > I tried that earlier, but the problem is: > > count( $chance ) - 1 ); returns a

Re: [PHP] Array difficulty

2007-07-31 Thread Alister Bulman
On 31/07/07, Carlton Whitehead <[EMAIL PROTECTED]> wrote: >> Couldn't you just do >> arsort($chance); >> $lastItem = chance[( count( $chance ) - 1 )]; > 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

RE: [PHP] Array difficulty

2007-07-31 Thread Chris Boget
> > Couldn't you just do > > arsort($chance); > > $lastItem = chance[( count( $chance ) - 1 )]; > $lastItem = end( $chance ); end() returns the value as well. You would also need to use key(). thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.ne

RE: [PHP] Array difficulty

2007-07-31 Thread Robert Cummings
On Tue, 2007-07-31 at 14:43 +0100, Chris Boget wrote: > > 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

Re: [PHP] Array difficulty

2007-07-31 Thread Robin Vickery
On 31/07/07, Carlton Whitehead <[EMAIL PROTECTED]> 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

Re: [PHP] Array difficulty

2007-07-31 Thread Chris Boget
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 Except he's looking for the key and not the value, whic

Re: [PHP] Array difficulty

2007-07-31 Thread Carlton Whitehead
[EMAIL PROTECTED]>, 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 th

RE: [PHP] Array difficulty

2007-07-31 Thread Chris Boget
> 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 v

Re: [PHP] Array difficulty

2007-07-31 Thread Richard Davey
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. Curre