View Full Version : Does PHP 5.x allow nested loops?
Michael Morris
07-12-2005, 02:19 PM
Cause 4 sure as hell don't and it's annoying the crap out of me. I've found you can next a foreach in a while, and then nest that in a for loop, but beyond that you're SOL. I'm writing a vote counting program and I need to have a four layer deep nested loop.
I'm so fustrated with it I'm about ready to write a visual basic program to do the job (I know how to set up the MyOBDC driver to do it).
The Geek
07-12-2005, 03:10 PM
I may be barking up a tree - however as far as I know you can nest all you want. FOr instance, this is perfectly valid and works:
foreach($array1 as $key1=>$value1){
foreach($value1 as $key2=>$value2){
foreach($value2 as $key3=>$value3){
foreach($value3 as $key4=>$value4){
echo("er... shall I go on?");
}
}
}
}
glad to see the indent feature works in php blocks ;)
Marco van Herwaarden
07-12-2005, 03:23 PM
Could you post some code samples, because it is for sure possible to create nested loops.
Michael Morris
07-12-2005, 04:05 PM
Nevermind, I strategically placed some echo statements to throw back the counters to the screen in the loops - it is looping, something else is wrong :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.