使用PHP和MySQL我已經生成了兩個數組。我想遍歷這些數組,從兩個數據中檢索數據並一起顯示在一個句子中。PHP foreach循環和數據檢索
foreach ($items as $item) {
if(isset($item->item_title)) {
$itemTitle = $item->item_title;
}
// var_dump($itemTitle);
// string(7) "Halfway" string(5) "Story" string(6) "Listen"
}
foreach ($aData["Items"]["Item"] as $a) {
if (isset($a['description'])) {
$aDescription = $a['description'];
}
// var_dump($aDescription );
// string(4) "Good" string(6) "Strong" string(2) "OK"
}
?>
預期結果;
The title is Halfway and the description is Good.
The title is Story and the description is Strong.
The title is Listen and the description is OK.
// etc
// etc
是否有可能巢foreach
迴路,或者有更好的更有效的方法?
請分享您的輸入數組。 –
不幸的是,我沒有這些數據。如果有某些方法或功能,你可以推薦我願意親自看看他們。我只需要在正確的方向輕推!邏輯拋棄了我:/ –
我希望我的文章能像你所期望的一樣幫助你。 –