我正在考慮將數組保存到文本文件以供以後訪問,但我很想知道保存此數組的更好方法是什麼?它真的只是一個意見問題!我真的只想知道什麼是更好的方法來保存這個以及爲什麼在第一部分有一個空的?使用PHP,Jquery&JSON的數組
{
"questionbanknames": "Question Bank Name",
"question": [null, {
"question": "This is question 1?",
"type": "manual",
"a": "",
"b": "",
"c": "",
"d": ""
}, {
"question": "This is question 2?",
"type": "multi",
"a": "yes",
"b": "no",
"c": "maybe",
"d": "all of the above"
}]
}
OR
"questionbanknames": "Question Bank Name",
"question[1][question]": "This is question 1?",
"question[1][type]": "manual",
"question[1][a]": "",
"question[1][b]": "",
"question[1][c]": "",
"question[1][d]": "",
"question[2][question]": "This is question 2?",
"question[2][type]": "multi",
"question[2][a]": "yes",
"question[2][b]": "no",
"question[2][c]": "maybe",
"question[2][d]": "all of the above"
這樣做更有意義,所以在這種情況下直接保存底部數組? – 2015-04-01 05:05:31
@MarkShaw底部數組不應該直接保存。而是'json_encode'並將生成的JSON保存到文件中。當你需要返回數據時,只需將文件內容讀入一個變量和'json_decode'變量。這會給你一個PHP對象/數組,然後你可以使用它。 – raidenace 2015-04-01 05:07:30
完美,這是有道理的!非常感謝! – 2015-04-01 05:10:27