Page 1 of 1

problems creating a multi-dimensional array

Posted: Fri Mar 05, 2004 1:16 pm
by redtux
I have several arrays in squence from a form, with keys

What I want to do is to get all the different arrays into one multidimensional array so I would have
field 1,field2, field3 etc for each key

I seem to keep getting "array" printed this is what I have thus far

Code: Select all

<?php
$myarray=array($id,$firstname);
foreach($myarray as $value)&#123;
echo $value;
&#125;

?>
(leaving off the array just errors)

any help appreciated

Posted: Sun Mar 07, 2004 1:18 pm
by JAM
As you are trying out multidimensional arrays, you need to loop past more than one (hence multi):

Code: Select all

$myarray = array(
        'id' => array(1,2),    
        'name' => array("JAM","Foo")    
    );
    foreach($myarray as $value) {
        foreach($value as $value2) { // missed this second loop
            echo $value2; 
        } 
    }
I have several arrays in squence from a form, with keys
Hope that helped abit further.