I'm using foreach to echo array multidimensional array.
I know there have another simple way but I want to try using foreach.
here is my code:
<?php
$cars = array(
array("Volvo", 22, 18),
array("BMW", 15, 13,
array(
'satu' => 'heelo'
)
),
array("Saab", 5, 2),
array("Land Rover", 17, 15,
array('satu','dua')
)
);
foreach ($cars as $kebal)
{
if (is_array ($kebal))
{
foreach ($kebal as $katak)
{
echo($katak);
echo "<br>";
echo "<br>";
}
}
else
{
echo ($kebal);
echo "<br>";
}
}
?>
and the output i get is :
Volvo
22
18
BMW
15
13
Notice: Array to string conversion in C:\xampp\htdocs\latihtubi\dataarray.php on line 42
Array
Saab
5
2
Land Rover
17
15
Notice: Array to string conversion in C:\xampp\htdocs\latihtubi\dataarray.php on line 42
Array
so, how to properly write the code? Thanks.
array('satu'=>'heelo'), just roll up a recursive function or use SPL