你好我無法弄清楚如何遍歷這個json編碼數組,併爲每個對象,獲取它的所有值。我需要將每個值作爲自己的變量。json_encode獲取值foreach對象
echo json_encode($formulars);
這是我所得到的,當我贊同它
[{"project_name":"polle","type":"support","title":"vi","reason":"prover","solution":"igen","comments":"okay ","date_stamp":"2013-08-20 14:06:37","used_time":132},{"project_name":"dolla","type":"support","title":"lolol","reason":"skl","solution":"dskal","comments":"kflafda ","date_stamp":"2013-08-20 14:11:36","used_time":210},{"project_name":"polle","type":"fejl","title":"lol","reason":"aksdl","solution":"fdjks","comments":"djsks ","date_stamp":"2013-08-20 14:13:27","used_time":1230}]
我已經試過這段代碼,我設法脫身,從第一個對象的PROJECT_NAME,這就是它:
foreach ($formulars as $current => $project_name) {
$project_name['project_name'];
}
那麼,有什麼辦法可以讓每個對象中的所有變量我的數組而不僅僅是PROJECT_NAME的?
像這樣:
foreach ($formulars as $current){
$projectName = $current['project_name'];
$type = $current['type'];
$reason = $current['reason'];
}
在此先感謝
嘗試json_decode(),那麼你可以訪問它。 – Parixit
「像這樣:」代碼似乎就足夠了。爲什麼它不工作?發生了什麼? – mario
哦,上帝馬里奧我竟然沒有測試出「這樣」的代碼,我只是快速輸入了它。我只是試了一下,它的工作。我覺得很愚蠢,呵呵。謝謝你! –