Jordy Jordy - 1 year ago 108
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.


Answer Source

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().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download