我正在尝试将所有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);
}