下面是數組的代碼。我試圖列出內部數組中的字段類別,並且當該字段爲空時寫入「無類別」。而我根本做不到。我一直試圖用兩個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
是的,我可以,但我只想添加「無類別」和所有其他類別只有一次... –