### Re: [PHP] Array difficulty

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. Currently, I'm doing

### [PHP] Array difficulty

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

### Re: [PHP] Array difficulty

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

### 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

### Re: [PHP] Array difficulty

(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

### 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? 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, which

### Re: [PHP] Array difficulty

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 value. Currently,

### RE: [PHP] Array difficulty

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

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:

### Re: [PHP] Array difficulty

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

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 an integer, so I