g8nwug
Last Updated: February 25, 2016
·
1.787K
· atulmy
Being rotaractor1

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.
Say Thanks
Respond