Re: getting the "next" element of an associative array

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

 



On Thu, July 12, 2007 1:34 am, Chris wrote:
> Olav Mørkrid wrote:
>> let's say we have the following associative array:
>>
>> $array = array(
>>  "red" => "ferrari",
>>  "yellow" => "volkswagen",
>>  "green" => "mercedes",
>>  "blue" => "volvo"
>> );
>>
>> then we have a current index into the array:
>>
>> $index = "yellow";
>> $current = $array[$index];
>>
>> now: how do i get the key of the next array element (in this case
>> "green")?
>>
>> $next = ?
>
> Funnily enough:
>
> $next = next($array);
>
> http://www.php.net/manual/en/function.next.php

No, he'll just get the first one, regardless of which array index he
has directly accessed with [] operator most recently...

Unless the OP is uber-PHP-expert, you've probably just made some bad
Design decisions along that way, and painted yourself into a corner
because of them.

Rather than write some hack function to find the element after the
element of an index you know, figure out where you went wrong back
when, and start over from there...

If you're playing adventure, and about to die a horrible death, maybe
the mistake was NOT the LAST move you made, but a little before that,
no? :-)

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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