我的代码如下:
foreach ($tmpArray as $keys => $values) {
if(is_array($values)) {
foreach ($values as $key => $value) {
if($key == "category_name"){
echo $value['category_name'];
}
}
} else {
if($keys == "category_name"){
echo $values;
}
}
}
输出:Vasıta-> Bmw X Serisi 我想这样做:Vasıta-> Bmw X Serisi-> Deneme
如何使用foreach
循环打印category_name?
答案 0 :(得分:0)
if (is_array($tmpArray)) {
echo isset($tmpArray['category_name']) ? $tmpArray['category_name'] . '->' : '';
foreach ($tmpArray as $key1 => $value1) {
if (is_array($value1)) {
echo isset($value1['category_name']) ? $value1['category_name'] . '->' : '';
foreach ($value1 as $key2 => $value2) {
if (is_array($value2)) {
echo isset($value2['category_name']) ? $value2['category_name'] : '';
}
}
}
}
}