|
Posted by Satya on 09/07/07 07:29
On Sep 7, 12:28 pm, Satya <satya61...@gmail.com> wrote:
> On Sep 7, 8:49 am, J. Frank Parnell <p...@edgecity.ufo> wrote:
>
>
>
> > On Thu, 06 Sep 2007 21:41:27 -0400, Jerry Stuckle <jstuck...@attglobal.net>
> > wrote:
>
> > >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.
>
> > Ah, cool, I saw similar on the php.net. Is there a way to do it so that it will
> > go thru all of both, even if one runs out?
>
> if (count ($arr1) > count($arr2)) {
> $len = count($arr1);}
>
> else {
> $len = count($arr2);
>
> }
>
> Now
>
> for($i=0; $i < $len; $i++) {
>
> list($key1, $val1) = @each($arr1);
> list($key2, $val2) = @each($arr2);
>
> }
>
> What about this?
> I have not checked this.
>
> http://satya61229.blogspot.com/
There I used "foreach" instead of "for".
[Back to original message]
|