Next key in the array
If the current()
pointer is on the right, @Thomas_Cantonnet is correct and you want to use next()
. If you did not iterate over the array through next (), you first need to go through the array to correctly set the internal index pointer:
$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()
.
you can use foreach
$test=array( 1=> array("a","a","a"), 2=> array("b","b","b"), 'a'=> array("c","c","c") ); foreach (array_keys($test) as $value) { foreach ($test[$value] as $subValue) { echo $subValue." - ".$value; echo "\n"; } echo "\n"; }
Exit
a - 1 a - 1 a - 1 b - 2 b - 2 b - 2 c - a c - a c - a
function get_next_key_array($array,$key){ $keys = array_keys($array); $position = array_search($key, $keys); if (isset($keys[$position + 1])) { $nextKey = $keys[$position + 1]; } return $nextKey;
// in the above function, the first argument is the array in which to search for the key, and the second argument is $ key, which is used to get the next key, so this means that you must get one existing key of the associative array from you, for which you want to get the following keys.