View Single Post
Old 03-01-2009, 01:15 AM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

This is because within the foreach loop you have moved the array pointer one place each time. After the foreach loop the pointer points to the very end of the array, and current will return NULL. However, if you reset the pointer of the array in between your loops as seen below, your second loop will loop correctly because the array pointer has been reset to the beginning.

This works like so because your second loop is not a foreach loop. A foreach automatically resets the array pointer before looping again.

php Code:
echo 'Current Index = ' . current($test) . "\n";
reset($test);
echo 'Current Index = ' . current($test) . "\n";
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
allworknoplay (03-01-2009)