RE: foreach and multiple arrays
| From: | Tim Ward | Date: | Mon, 30 Jul 2001 09:15:54 +0000 |
| Subject: | RE: foreach and multiple arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-60176@lists.php.net to get a copy of this message | ||
Why can't you create the arrays as associative arrays in the first place
$fred[] =
array("title"=>"Apple","value"=>"Red","size1"=>"10","size2"=>"20");
$fred[] =
array("title"=>"Banana","value"=>"Yellow","size1"=>"10","size2"=>"20");
then
foreach($fred as $thisfred)
foreach ($thisfred as $key=>$value) ... do whatever ...;
Tim
----------
From: Chris Aitken [SMTP:chris@ideal.net.au]
Sent: 30 July 2001 02:40
To: php-general@lists.php.net
Subject: foreach and multiple arrays
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: chris@ideal.net.au phone: +61 2 4628 8888 fax: +61 2 4628
8890
__-----------------------------------------__
*** Big Brother ***
It just shows that the dull will rule the world. And we will be
watching it.