I want to form multidimensional array in with code...Something like that:

$data = array( 
    array( "Mike", "3" => 1, "4" => 0, "5" => 0), 
    array( "Steve", "3" => 0, "4" => 0, "5" => 0),
    array("John", "3" => 0, "4" => 0, "5" => 0),
     );

What code should be to get this result

 Array
(
[Mike] => Array
    (
        [3] => 1
        [4] => 0
        [5] => 0
    )

[Steve] => Array
    (
        [3] => 0
        [4] => 0
        [5] => 0
    )

[John] => Array
    (
        [3] => 0
        [4] => 0
        [5] => 0

    )
)

Thanks

share|improve this question
2  
Is this a code request or a question? – Baszz Aug 19 '11 at 13:33
1  
what is the difference? – user812129 Aug 19 '11 at 13:37
2  
If it's a code request, the site you're looking for is elance.com or equivalent. – Laurent Aug 19 '11 at 13:40
1  
That you should write your own code and come to this place if you get stuck on something and ask a proper question on which we can give an answer that get's you going. – Baszz Aug 19 '11 at 13:40

closed as too localized by NullUserException Mar 16 '12 at 19:53

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

3 Answers

$data = array( 
    "Mike" => array("3" => 1, "4" => 0, "5" => 0), 
    "Steve" => array("3" => 0, "4" => 0, "5" => 0),
    "John" => array("3" => 0, "4" => 0, "5" => 0),
     );

Like that?

A multidimensional array is just an array with another array as its value:

$array = array("key" => array("Array inside an array"));
share|improve this answer
No ... it gets diffrent result – user812129 Aug 19 '11 at 13:37
Array ( [0] => Array ( [Mike] => Array ( [3] => 1 [4] => 0 [5] => 0 ) ) – user812129 Aug 19 '11 at 13:37
@user812129 Try now. – Andre Backlund Aug 19 '11 at 13:41
$data = array( 
    "Mike"=>array("3" => 1, "4" => 0, "5" => 0), 
    "Steve"=>array("3" => 0, "4" => 0, "5" => 0),
    "John"=>array("3" => 0, "4" => 0, "5" => 0),
);
share|improve this answer
That's it thanks... How can I acces to "Mike" and how to acces to Mike's first element (3=>1)? – user812129 Aug 19 '11 at 13:43
$data = array( 
    "Mike" => array(3 => 1, 4 => 0, 5 => 0), 
    "Steve" => array(3 => 0, 4 => 0, 5 => 0),
    "John" => array(3 => 0, 4 => 0, 5 => 0)
);
share|improve this answer
That's it thanks... How can I acces to "Mike" and how to acces to Mike's first element (3=>1)? – user812129 Aug 19 '11 at 13:42
$data['Mike'][3] – Josh Aug 19 '11 at 13:46
$data["Mike"] and $data["Mike"][3] – Karsten Aug 19 '11 at 13:46
if I write foreach($data as $row) I only get array of numbers... How do I get "Mike"? – user812129 Aug 19 '11 at 13:58
I got it... foreach($data as $key=>$name) – user812129 Aug 19 '11 at 14:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.