Posted by Jerry Stuckle on 05/21/07 01:24
levidicom@gmail.com wrote:
> foreach($test as $var1){
>
> foreach($test2 as $var2)
> {
>
>
>
> echo '"var1: " . $var1[1] . "<br>"var2: " . $var2[1] . "<br>
> \n"';
> }
> }
>
> --------------------
>
> 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
>
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.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|