我有一個數組寫入和讀取與指定數組中的鍵爲JSON文件
$monthlyStatistics = array('total' => 1, 'opened' => 1, 'clicked' => 1, 'bounced' => 1, 'optout' => 1);
,我已經保存到一個JSON文件
$monthlypath = '/storage/monthlytotals.json';
file_put_contents($monthlypath, json_encode($monthlyStatistics));
,我需要閱讀該JSON文件和使用指定的鍵將內容作爲數組輸出。我目前做這個:
$monthlypath = '/storage/monthlytotals.json';
$read_file = file_get_contents($monthlypath);
$monthlytotals = json_decode($read_file);
我知道file_put_contents把爲一個字符串,該文件()應該將整個文件讀入一個數組(我目前沒有使用,因爲它不讀什麼file_put_contents寫道)。
我在做這個錯誤還是我錯過了一個函數,應該與file()一起寫入數組?
你看了['json_decode()'](http://php.net/manual/en/function.json-decode.php)的文檔嗎? – axiac
是的我已閱讀文檔 – Cyberio