Last Updated: February 25, 2016
·
3.944K
· atulmy

PHP: Traverse an array without (for, foreach, each)

// Example Array
$loopArray = array(
    'mango' => 'yellow',
    'grapes' => 'violet',
    'apple' => 'red',
);

reset($loopArray); // move internal pointer to the start of the array
while (current($loopArray)) {
    echo key($loopArray); // print the current key of array
    echo current($loopArray); // print the current value of array
    next($loopArray);
}
</code></pre>

Reference.