Let's say I have a info.JSON file on my server, with the following data:
{"firstName":"John","age":"37"}
And in PHP, I want to add another key/value pair (somebody's middle name for example) to the info.JSON file.
If I use the file_put_contents()
function, that will overwrite the file completely. For example:
$middleName = array("middleName" => "Bill");
file_put_contents("info.json",json_encode($middleName));
The content of the info.JSON file would now be :
{"middleName":"Bill"}
How can I simply add more key/value pairs to an existing .JSON file without overwriting it?
Thanks.