Re: Array difficulty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
To: "Carlton Whitehead" <carlton.whitehead@xxxxxxxxxxxx>, php-general@xxxxxxxxxxxxx
Sent: Tuesday, July 31, 2007 9:43:00 AM (GMT-0500) America/New_York
Subject: RE:  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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux