Multidimensional array construction
| From: | Darren Gamble | Date: | Mon, 03 Dec 2001 23:36:39 +0000 |
| Subject: | Multidimensional array construction | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-76430@lists.php.net to get a copy of this message | ||
Here's a question for the list:
I have a two-dimensional array; essentially a list of arrays. Each element
(an array) can have any number of elements. As a small example:
(
( "foo" , "bar" , "red" , "apple" ),
( "foo" , "bar" , "red" , "car"),
( "foo" , "green" )
)
I would like to traverse this array and place all of the data into another
multidimensional array. The following statements illustrate how I'd like to
do this from the example:
$myarray["foo"]["bar"]["red"]["apple"] = $some_value1;
$myarray["foo"]["bar"]["red"]["car"] = $some_value2;
$myarray["foo"]["green"] = $some_value3;
Is there any way to easily do this in PHP? I could "cheat" and use eval(),
but there is probably a better way. I have thought of using each() or
references, but nothing has come to mind so far.
Any ideas? Should I just use eval() ?
============================
Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948