Next key in array
$next = next($array);
echo key($array);
Should return the key corresponding to $next;
next($array);
$key = key($array);
prev($array);
If pointer is not on this element, as other solutions assume, You can use
<?php
$keys = array_keys($arr);
print $keys[array_search("gsda",$keys)+1];
Update: Note that this is not a valid answer, as it's searching for values instead of keys.
If the pointer of current()
is on the right key, @Thomas_Cantonnet is right and you want to use next()
. If you did not iterate through the array via next(), you first have to go through the array to set the internal index pointer correctly:
$search = "bsdf";
while (($next = next($array)) !== NULL) {
if ($next == $search) {
break;
}
}
Now $next points to your current search-index and you can iterate over the rest via next()
.