-2
我想将所有json文件合并为一个。但是,我总是收到一个空的json文件。这是代码;将许多json文件合并为一个
function mergejson()
{
$events = array();
// open each jsonfile in this directory
foreach(glob("*.json") as $filename) {
// get the contents of the the current file
$data[] =json_decode($filename, true);
$events= array_merge($events,$data);
}
$file_name ='merge.json';
$events =json_encode($events,true);
file_put_contents($file_name,$events);
}
请原谅我的知识的缺乏,我是初学者,你可以建议任何代码作为一个解决方案。 – Gvep
只需用'json_decode(file_get_contents($ filename),true)替换'json_decode($ filename,true);'并且它应该可以工作! – cb0
表示运行良好,谢谢! – Gvep