這是我想編碼成JSON的數組的var_dump:PHP JSON編碼不工作
array(3) {
[0]=> array(2) {
["From"]=> string(14) "08 August 2013"
["To"]=> string(14) "21 August 2013"
}
[1]=> array(2) {
["From"]=> string(14) "11 August 2013"
["To"]=> string(14) "21 August 2013"
}
[2]=> array(2) {
["From"]=> string(14) "12 August 2013"
["To"]=> string(14) "01 August 2013"
}
}
當我進行編碼,輸出看起來是這樣的:
[
{"From":"08 August 2013","To":"21 August 2013"},
{"From":"11 August 2013","To":"21 August 2013"},
{"From":"12 August 2013","To":"01 August 2013"}
]
但我想它是這樣的:
{
0:{"From":"08 August 2013","To":"21 August 2013"},
1:{"From":"11 August 2013","To":"21 August 2013"},
2:{"From":"12 August 2013","To":"01 August 2013"}
}
這是可能的,因爲我以前做過,但使用相同的代碼,現在它不會工作
嘗試'json_encode($陣列,JSON_FORCE_OBJECT)'。不知道它是否會工作,誠實。 – Phas1c