[PHP] foreach and multiple arrays

2001-07-29 Thread Chris Aitken


Hi guys,

Something ive been working on and not having much success is this. I am 
writing a function, and I want to be able to feed it the following -

function_name (
 array("Apple","Red","10","20"),
 array("Banana","Yellow","10","20")
 );


now, basically what I want to be able to do is, take each array andlist 
each entry in the array as a variable.. eg..

(first loop run)
$title="Apple";
$value="Red";
$size1="10";
$size2="20";

(first loop run)
$title="Banana";
$value="Yellow";
$size1="10";
$size2="20";



etc. The function may have any number of entries (1 onwards) etc. I have 
played with foreach() and other variants, but I just cant seem to find the 
right combo of code to get it working.

Any help would be appreciated.


Cheers


Chris


--
 Chris Aitken - Administration/Database Designer - IDEAL Internet
  email: [EMAIL PROTECTED]  phone: +61 2 4628   fax: +61 2 4628 8890
  __-__
   *** Big Brother ***
It just shows that the dull will rule the world. And we will be watching it.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] foreach and multiple arrays

2001-07-29 Thread Jan Wilson

* Chris Aitken <[EMAIL PROTECTED]> [010729 19:44]:
> Something ive been working on and not having much success is this. I am 
> writing a function, and I want to be able to feed it the following -
> 
> function_name (
>  array("Apple","Red","10","20"),
>  array("Banana","Yellow","10","20")
>  );
> 
> now, basically what I want to be able to do is, take each array andlist 
> each entry in the array as a variable.. eg..
> 
> (first loop run)
> $title="Apple";
> $value="Red";
> $size1="10";
> $size2="20";
> 
> (first loop run)
> $title="Banana";
> $value="Yellow";
> $size1="10";
> $size2="20";
> 
> etc. The function may have any number of entries (1 onwards) etc. I have 
> played with foreach() and other variants, but I just cant seem to find the 
> right combo of code to get it working.

This seems to work.

$array2d = array(
array("Apple","Red","10","20"),
array("Banana","Yellow","10","20")
);
foreach($array2d as $rowNum => $rowVal) {
print "Row $rowNum:\n";
print "Title is $rowVal[0]\n";
print "Value is $rowVal[1]\n";
print "Size1 is $rowVal[2]\n";
print "Size2 is $rowVal[3]\n";
};

Maybe it will give you a place to start.

-- 
Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize |  /'  chetumal.com & linux.bz
Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]