How to declare and print multidimensional array in PHP

1 Answer

0 votes
$arr =  Array ( 
        0 => Array 
        ( 
            'id' => 13, 
            'name' => "R2D2",
            'description' => "A resourceful astromech droid",
            'price' => 10000000
        ),
        1 => Array 
        ( 
            'id' => 19, 
            'name' => "C-3PO", 
            'description' => "droid programmed for etiquette and protocol",
            'price' => 7000000 
        ), 
);

foreach ($arr as $key => $value) {
    foreach ($value as $ky => $val) {
        echo "$ky: $val<br />"; 
    }
    echo "<br />";
}

/*
run: 
 
id: 13
name: R2D2
description: A resourceful astromech droid
price: 10000000

id: 19
name: C-3PO
description: droid programmed for etiquette and protocol
price: 7000000
 
*/

 



answered Jul 26, 2017 by avibootz

Related questions

2 answers 343 views
343 views asked Jun 28, 2021 by avibootz
2 answers 558 views
2 answers 506 views
2 answers 467 views
...