Forum Moderators: coopster

Message Too Old, No Replies

calling array values

         

sssweb

12:55 am on Feb 12, 2006 (gmt 0)

10+ Year Member



I have an array from which I want to call the next value after a given $value. For example, in:

$array (
0 => "zero",
1 => "one",
2 => "two"
)

If $value = 'one', I want to call the next one: 'two'.

I tried using:

$mykey = array_search('one', $array); // $mykey now = 1

Is there a way to return the array value where $key = $mykey + 1?

Or some other way?

DrDoc

12:57 am on Feb 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo $array[array_search('one', $array) + 1];

sssweb

5:25 pm on Feb 12, 2006 (gmt 0)

10+ Year Member



Thanks Doc -- works like a charm.