【发布时间】:2017-03-09 10:21:56
【问题描述】:
我想使用存储过程创建一个 JSON 文件,并在我的表数据发生更改时更新该 jsonfile。我不知道该怎么做。请问谁能帮我解决这个问题?
【问题讨论】:
标签: php json codeigniter-3
我想使用存储过程创建一个 JSON 文件,并在我的表数据发生更改时更新该 jsonfile。我不知道该怎么做。请问谁能帮我解决这个问题?
【问题讨论】:
标签: php json codeigniter-3
<?php
$someNewData = array("foo"=>"bar"); //example
if(!file_exists("./data.json")) {
$file = fopen('data.json', 'w');
fwrite($file, '');
fclose($file);
}
$jsonData = json_decode(file_get_contents("./data.json"), true);
if(!is_array($jsonData)){$jsonData=array();}
if(isset($someNewData) && is_array($someNewData)){
file_put_contents("./data.json", json_encode(array_merge($someNewData, $jsonData)));
}
希望对你有帮助:)
【讨论】: