problems creating a multi-dimensional array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
redtux
Forum Newbie
Posts: 7
Joined: Thu Mar 04, 2004 8:40 am

problems creating a multi-dimensional array

Post 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
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply