I have a strange situation with my PHP code.
Basically I want to output the JSON of all the JSON files I have in a directory, but for an unexpected reason it gives me two JSON arrays, one is wrong and one is correct.
Here's the code:
$files = glob("players/*");
$nFiles = count($files);
foreach($files as $file){
$jsonArray[] = array(
"name" => "a name",
"reason" => "a reason",
"date" => "a date"
);
echo json_encode($jsonArray);
}
Output:
[{"name":"a name","reason":"a reason","date":"a date"}] -- here the loop stops (idk why) and it begins again -- [{"name":"a name","reason":"a reason","date":"a date"},{"name":"a name","reason":"a reason","date":"a date"}]
Aucun commentaire:
Enregistrer un commentaire