下面是数组的代码。我试图列出内部数组中的字段类别,并且当该字段为空时写入“无类别”。而我根本做不到。我一直试图用两个foreach嵌套将列表保存到一个新的数组中,但我不能完全正确地使用它。如何从3D数组内部数据中创建列表PHP
Array(
'type' => 'success',
'value => array (
0 => array (
'id' => 1,
'joke' => 'Chuck Norris uses ribbed condoms inside out, so he gets the pleasure.',
'categories' => array());
1 => array (
'id' => 2,
'joke' => 'MacGyver can build an airplane out of gum and paper clips. Chuck Norris can kill him and take it.',
'categories' => array(
[0] => nerdy
));
2 => array (
'id' => 3,
'joke' => 'MacGyver can build an airplane out of gum and paper clips. Chuck Norris can kill him and take it.',
'categories' => array(
[0] => explicit
));
);
)
//这是我想没有运气
$output = array();
foreach($response as $row){
foreach($row as $cat){
$output[] = $cat['categories'];
}
}
谢谢!
你想做什么,如果它是空的?在'$ output'中添加“无类别”或回显这个文本? – olibiaz
是的,我可以,但我只想添加“无类别”和所有其他类别只有一次... –