你好,我已經解碼了一個json字符串,我發送到我的服務器,我試圖從他的價值。訪問數組值爲空
我的問題是,我不能從內部數組獲取值。
這是我的代碼:
<?php
$post = file_get_contents('php://input');
$arrayBig = json_decode($post, true);
foreach ($arrayBig as $array)
{
$exercise = $array['exercise'];
$response["exercise"] = $exercise;
$response["array"] = $array;
echo json_encode($response);
}
?>
當我從我的$response
的答案,我得到這個值:
{"exercise":null,"array":[{"exercise":"foo","reps":"foo"}]}
爲什麼$array['exercise']
空,如果我可以看到,是不是空的array
謝謝。
您應該執行'var_dump($ arrayBig)'。你可能會看到你的數組中有另一個數組。 – jeroen
我建議你啓用'display_errors'並將'error_reporting'設置爲'E_ALL'。你有一個未定義的索引錯誤'$ array ['exercise']' – Phil