我有一个多维数组,当我使用 print_r 时,它看起来像这样:
Array (
[car] => Array (
[72] => Camry
[62] => Lexus
[55] => honda
[44] => toyota
)
[Job] => Array (
[70] => Bookstore
[73] => Cafe
)
[City] => Array (
[68] => Wisconsin
[63] => Chicago
[47] => New York City
[46] => Los Angeles
)
)
这是一个父/子多维数组。可以有任意数量的父母和任意数量的孩子。
如何回显一个多维数组,使其看起来像这样
Car
Camry
Lexus
honda
toyota
Job
Bookstore
Cafe
City
Wisconsin
Chicago
New York City
Los Angeles
我尝试打印多维数组:
function RecursiveWrite($array) {
foreach ($array as $vals) {
echo $vals['parent'] . "\n";
RecursiveWrite($vals['child']);
}
}
RecursiveWrite($categories); // $categories is the name of the array
当我运行代码时,这不会打印出任何输出。有什么建议么?