Re: [PHP] Array difficulty
- From: abulman@xxxxxxxxx ("Alister Bulman")
- Date: Tue, 31 Jul 2007 15:08:54 +0100
On 31/07/07, Carlton Whitehead <carlton.whitehead@xxxxxxxxxxxx> 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 $chance[0], neither of which exist in the array. Keep in mind $chance only has keys with string names:
http://uk3.php.net/current
$chance = array("lowercase" => 27, "uppercase" => 62, "integer" => 46);
arsort($chance);
$lastItem = current($chance);
echo "$lastItem\n\n"; // 62
Alister
.
- Follow-Ups:
- Re: [PHP] Array difficulty
- From: "Robin Vickery"
- Re: [PHP] Array difficulty
- References:
- Re: [PHP] Array difficulty
- From: Carlton Whitehead
- Re: [PHP] Array difficulty
- Prev by Date: Senior PHP Role
- Next by Date: Re: if inside an echo.
- Previous by thread: Re: [PHP] Array difficulty
- Next by thread: Re: [PHP] Array difficulty
- Index(es):