PHP如何把JSON字符串轉為數組
在PHP中可以使用“json_decode()”函數把JSON字符串轉為數組,該函數的作用對JSON格式的字符串進行解碼,其語法為“json_decode(str,assoc)”,使用時將字符串傳入第1個參數并將第2個設置為TRUE即可。
示例代碼:
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json, true));
打印結果:
array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) }
推薦教程:《PHP教程》