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
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
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
> > 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
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
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
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
[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
> 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
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
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);
foreac
11 matches
Mail list logo