-1
我的PHP代码有一个奇怪的情况。
基本上我想输出目录中所有JSON文件的JSON,但是出于意想不到的原因,它给了我两个 JSON数组,一个是错误的,一个是正确的。
下面的代码:JSON循环给出的数组超出预期
$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);
}
输出:
[{"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"}]
也许你需要把你的'echo'下来自'foreach'的闭括号# – Daan
DAMMIT!没有看到它。谢谢,朋友 –