I want to create a php script that loads all my files (.pdf) from the 3 directory and create a json file.
I try this
$dir_2016 = \"./HCL/2016\";
$dir_201
You should move your definition of $json_file to bottom as follow:
// ... get files code
$json_file = array(
"2016" => $files_2016,
"2015" => $files_2015,
"2014" => $files_2014,
);
echo json_encode($json_file);
Because array is passing by value rather than passing by reference.
And, a better way to get files and sub-directories in a directory shallowly is use scandir, for example:
$files_2014 = array_slice(scandir('./HCL/files_2014'), 2)
See: http://php.net/manual/en/function.scandir.php