我通過一個多維數組試圖循環,但在foreach循環中,它只是輸出錯誤遍歷PHP多維數組
指數「名」未找到。索引 '卡路里' 不創始人
foreach($responsex['foods'] as $fx5)
{
echo($fx5['name']);
echo($fx5['calories']);
}
響應:即$ responsex
陣列( 'encodedId'=> '4H8xxx', '的displayName'=> 'SAM',)陣列(3){「foods」] => array(3){[0] => array(5){[「isFavorite」] => bool(false) [「logDate」] => string(10) 「2016-04-15」[「logId」] => int(7139364449) [「loggedFood」] => array(10){[「accessLevel」] => string(6)「PUBLIC」 [「amount」 ] => int(2)[「brand」] => str (0)「[」calories「] => int(574) [」foodId「] => int(536497687)[」locale「] => string(5)」en_AU「 [」mealTypeId「] = > int(7)[「name」] => string(14)「Potato Pudding」 [「unit」] => array(3){[「id」] => int(91)[「name」] = > string(3)「cup」 [「plural」] => string(4)「cups」} [「units」] => array(8){[0] => int(6754) [1] = > int(91)[2] => int(256)[3] => int(279)[4] => int(226)[5] => int(180)[6] => int (6){[「calories」] => int(574)[「carbs」] => float(49.16)[「fat」)[7] => int(389)}} [「nutritionalValues」] => 「]> => float(34.98)[」fiber「] => float(3.6)[」protein「] => float(16.1) [」sodium「] => int(1524)}} [1] => array(5){[「isFavorite」] => bool(false)[「logDate」] => string(10)「2016-04-15」[「logId」] => (10){['accessLevel「] => string(6)」PUBLIC「[」amount「] => int(1)[」brand「] => string(0)「」 [「calories」] => int(359)[「foodId」] => int(535239347)[「locale」] => string(5)「en_AU」[「mealTypeId」] = > int(7)[「name」] => string(54)「Fish, Cheese Sauce(Mixture)中的麪條和蔬菜」[「unit」] => array(3) {[「id」] => int(91)[「name」] => string(3)「cup」[「plural」] => string(4) 「cups」} [「units」] => array(8){[0] = > int(6837)[1] => int(91)[2] => int(256)[3] => int(279)[4] => int(226)[5] => int(180 (6){[「calories」] => int(359)[「碳水化合物」)[6] => int(147) [7] => int(389)}} [「nutritionValues」 ] => float(28.01)[「fat」] => float(14.05)[「fiber」] => float(2.9)[「protein」] => float(29.08)[「sodium」] => int(534)}} [2] => array(5){[「isFavorite」] => bool(false )[「logDate」] => string(10) 「2016-04-15」[「logId」] => int(7138326866)[「loggedFood」] =>數組(10){ [「accessLevel」] = > string(6)「PUBLIC」[「amount」] => int(1)[「brand」] => string(0)「」[「calories」] => int(157)[「foodId」] = > int(536493638) [「locale」] => string(5)「en_AU」[「mealTypeId」] => int(7)[「name」] => string(11)「Cashew Nuts」[「unit 「] => array(3){[」id「] => int(226) [」name「] => string(2)」oz「[」plural「] => string(2)」oz「} [「units」] => array(4){[0] => int(226)[1] => int(180)[2] => int(147)[3] => int(389) }} [「nutritionalValues」] => array(6){[「calories」] => int(157) [「carbs」] => float(8.56)[「fat」] => float(12.43)[「fiber」] => float(0.9) [「protein」] => float(5.17) ] =「0」)=> int(3)}}} [「goals」] => array(2){「calories」] => int(1161)[「estimatedCaloriesOut」] => int(1411) 「=>數組(7){[」calories「] => int(1090) [」carbs「] => float(85.73)[」fat「] => float(61.46)[」fiber「] => float(7.4) [「protein」] => float(50。35)[ 「鈉」] => INT(2061)[ 「水」] => INT(0)} }
您可以爲我們使用的3v4l.org。你的陣列很大,可以用來調試。 –
使用print_r或json_encode顯示結果 – dev