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.
Written by Atul Yadav
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#