nested loop

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
foreach($test as $var1){

    foreach($test2 as $var2)

                  echo '"var1: " . $var1[1] . "<br>"var2: " . $var2[1] . "<br>


The $tests have values  just that this nested loop doesnt work i keep
getting this error message

Warning: Invalid argument supplied for foreach()

What is the correct way to nest a foreach
Thanks alot

Re: nested loop wrote:
Quoted text here. Click to load it

What this is saying is that $test2 is not an array.

Also, $var1[1] will not work unless $test is a two dimensional array.  
The same is true for $var2[1] and $test2.

There isn't anything special about nesting foreach() loops.  Something like:

   foreach ($array1 as $element1) {
     foreach $array2 as $element2)

works just fine.  It's just important to remember that array2 will be  
processed in its entirety for each element of array1.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline