>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
json_decode($string[, $assoc = false]):對 JSON 格式的字符串進行解碼
1.string:待解碼的字符串。
2.bool類型,為true時返回array而非object。
json_encode($value):對變量進行json編碼。
file_get_contents($filename):將整個文件讀入一個字符串。
file_put_contents($filename,$data):將一個字符串寫入文件。
1.filename:將要寫入數據的文件名。
2.data:要寫入的數據。
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
首先:先把txt原來有的讀出來
$temStr=file_get_contents("files/user.txt");
接着:將獲取出來的json變成數組
$tempArray=json_decode($temStr,true);
然后:合並原來的數組和你要傳入新的數組。
$newnewArray=array_merge($tempArray,$newArray);
然后:將數組轉成json串
$jsonStr=json_encode($newnewArray);
最后:將json寫入文件
file_put_contents("files/user.txt",$jsonStr);