我有一個看起來像這樣的數組:Array ( [0] => Array ( [id] => 3434 [label] => some test label ) )我需要從這個數組中獲取 id 和標簽。所以我試過這個:foreach($results['id'] as $result) { echo $result['label'], '<br>';}但這沒有做任何事情,它給了我這個錯誤:PHP Notice: Undefined index: id in有人可以就這個問題提出建議嗎?提前致謝。
2 回答

慕妹3242003
TA貢獻1824條經驗 獲得超6個贊
嘗試
foreach($your_array as $temp){
echo $temp["id"];
echo $temp["label"];
}

寶慕林4294392
TA貢獻2021條經驗 獲得超8個贊
是多維數組。您可以像這樣從數組中獲取 Id 和標簽值:
foreach($results as $result)
{
echo $result['label'].'<br>';
echo $result['id'].'<br>';
}
- 2 回答
- 0 關注
- 212 瀏覽
添加回答
舉報
0/150
提交
取消