Answer the question
In order to leave comments, you need to log in
Why is only the last element returned?
I get a list of files. I want to return them in JSON , but only the last element is returned.
<?
$files = array_diff(scandir("plug/lol/"), ['.','..']);
$array = [];
$lole = [
"count" => count($files)
];
//echo json_encode($lole);
foreach($files as $key=>$lol){
$array = [
"response" => [
"count" => 16,
"items" => [
[
"id"=>"$lol",
"is_dir"=> "true"
],
] ]];
}
print_r($array);
?>
Answer the question
In order to leave comments, you need to log in
I want to return them in JSON , but only the last element is returned.
heh, a year has passed, and still no answer.
did you figure out what the problem is?
foreach($files as $key=>$lol){
//$array = [//это неправильно
$array[] = [ //это правильно
"response" => [
"count" => 16,
"items" => [
[
"id"=>"$lol",
"is_dir"=> "true"
],
] ]];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question