我在foreach上使用json_encode,它返回多个值,我只希望在foreach完成后只返回一个值
foreach($tree as $file) {
$arr = array('success'=>'ok');
echo json_encode($arr);
}
{"success":"ok"}{"success":"ok"}{"success":"ok"}{"success":"ok"}{"success":"ok"}{"success":"ok"}
预期产量
{"success":"ok"}
答案 0 :(得分:2)
执行以下操作:
foreach($tree as $file) {
$arr = array('success'=>'ok');
}
echo json_encode($arr);
输出将与预期的一样: {"success":"ok"}