Home » Php » how to adjust my array output

how to adjust my array output

Posted by: admin September 25, 2018 Leave a comment


Ouch… i just cant get it…
online i can set things right:
but on my live server its not working… 🙁

help needed.

if my array has single item than my responce looks like this:


and thats ok with me.

but if my array has more then one file, responce then looks like this:


how do i adjust my responce to be as first one?



sorry… heres my code:

more details here: I need to check if certain number is in string of numbers

header('Access-Control-Allow-Origin: *');
$imagesDir = '';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);

$find = 1;
//$filtered = preg_grep("/.*?\." . $find . "\./", $images);

$filteredImages = [];
foreach($images as $image) {
    $current_date = date("Ymd");
    $file_date = substr($image, 0, 8);
    if (strcmp($current_date, $file_date)>=0)
        $filteredImages[] = $image;
//$result = [];
$filtered = preg_grep("/.*?\.\d*" . $find . "\d*\./", $filteredImages);
$result = $filtered;

echo json_encode($result, JSON_UNESCAPED_UNICODE);