Jordy Jordy - 8 months ago 64
PHP Question

Next key in array

I have an array:


How can I get the name of the next key? For example if the current array is gsda, I need bsdf.



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

Now $next points to your current search-index and you can iterate over the rest via next().