Ali Yiğit Ali Yiğit - 4 months ago 8x
JSON Question

combine many json files into one

I am trying to combine all json files into one.However i always receive an empty json file . Here is code ;

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);

cb0 cb0

The function json_decode takes a string as first argument, not a filename!

So you have to load the file content, try using file_get_contents