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

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

 



Olav Mørkrid wrote:
chris

for your suggestion to work, the internal array pointer of $array
would first have to be set to point to the current element ($index).

but how do you do this?

this may seem like childs play, but i actually can't find any
documented php function for this. it would be something like:

My apologies - I misread your post. I just thought you wanted the next record, not the next key.

Jim's function looked pretty easy and simple :)

On 12/07/07, Chris <dmagick@xxxxxxxxx> 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


--
Postgresql & php tutorials
http://www.designmagick.com/




--
Postgresql & php tutorials
http://www.designmagick.com/

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