I was trying to print some image details as a JSON array for that I just wrote a PHP code. Now it is printing only JSON objects like {"image0":"iphone.png","image1":"bbg.jpg"}, But I want it to be formatted as {"images":[{"image0":"iphone.png"},{"image1":"bbg.jpg"}]}. Please someone help me to fix this.
code
<?php
$return_array = array();
$files = glob('tmp/*');
$files = array_filter($files,create_function('$file','return (!is_dir($file));'));
usort($files,create_function('$a,$b','return filemtime($b) - filemtime($a);'));
foreach($files as $key => $file)
{
$return_array["image".$key] = basename($file);
}
echo json_encode($return_array);
?>
[{"image0":"iphone.png"},{"image1":"bbg.jpg"}]makes little sense. Why not have an array of strings?["iphone.png", "bbg.jpg"].echo json_encode(array("images" => $return_array));???