You are here: Re: can you foreach() two arrays at once ? « PHP Programming Language « IT news, forums, messages
Re: can you foreach() two arrays at once ?

Posted by Jerry Stuckle on 09/07/07 01:41

J. Frank Parnell wrote:
> Hello,
> So, I was wondering how to do this:
>
> foreach($foo as $k=>$v AND $bar as $k2=>$v2){
> echo '<TR><TD>$k</TD><TD>$v</TD><TD>$k2</TD><TD>$v2</TD></TR>;
> }
>
> Thanks,

No.

However, you can use "each" to do the same thing, i.e.

reset $array1;
reset $array2;

for ((list($key1, $val1) = each($array1)) &&
(list($key2, $val2) = each($array2)) {
// $key1 and val1 contain the key and value for an element in $array1
// $key2 and val2 contain the key and value for an element in $array2
// Do your stuff here
}

It will stop as soon as you run out of elements in either array.
--
==================
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

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