You are here: Re: nested loop « PHP Programming Language « IT news, forums, messages
Re: nested loop

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация