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/11/07 15:00

J. Frank Parnell wrote:
> On Mon, 10 Sep 2007 21:13:34 -0400, Jerry Stuckle <jstucklex@attglobal.net>
> wrote:
>
>
>>> Now, I go to test things and of course, I forgot one big detail. The two arrays
>>> are actually multidimensional themselves:
>>> $a[0] = array('a[0]key1' => 'a[0]val1', 'a[0]key2' => 'a[0]val2');
>>> $a[1] = array('a[1]key1' => 'a[1]val1', 'a[1]key2' => 'a[1]val2');
>>> $b[0] = array('b[0]key1' => 'b[0]val1', 'b[0]key2' => 'b[0]val2', 'b[0]key3' =>
>>> 'b[0]val3');
>>> $b[1] = array('b[1]key1' => 'b[1]val1', 'b[1]key2' => 'b[1]val2', 'b[1]key3' =>
>>> 'b[1]val3');
>>> $b[2] = array('b[2]key1' => 'b[2]val1', 'b[2]key2' => 'b[2]val2', 'b[2]key3' =>
>>> 'b[2]val3');
>>>
>>> More like that. $a and $b are db results (arrays). Each element has its own
>>> array of feild=>value.
>>>
>>> I tried a couple things, nesting those scripts inside each other, but to no
>>> avail.
>>>
>> So, what is it exactly you want?
>
> Same as before, go through each array, for each element, list all the
> key=>values for both:
> $a[0][key]-val -- $b[0][key]-val
> // etc for all key-vals in $a[0] and $b[0]
> $a[1][key]-val -- $b[1][key]-val
> //etc
>
>

OK, so just create an inner loop similar to the existing one, which goes
through each of the elements in the arrays.

--
==================
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

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