Home » Php » how to adjust my array output

how to adjust my array output

Posted by: admin September 25, 2018 Leave a comment

Questions:

Ouch… i just cant get it…
online i can set things right:
http://sandbox.onlinephpfunctions.com/code/492fa3050bf906b4a6c0631bdb66b7f066f23034
but on my live server its not working… 🙁

help needed.

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

["20180517_xxxxxxxxxx-xxxxxxxxxxx~20180530.123456789.jpg"]

and thats ok with me.

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

{"0":"20180517_xxxxxx-xxxxx~20180530.123456789.jpg","2":"20180519_xxxx-xxxxx~20180530.1.jpg"}

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

["20180517_xxxxxx-xxxxxx~20180530.123456789.jpg","20180519_xxxxx-xxxxx~20180530.1.jpg"]

thanx!

sorry… heres my code:

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

<?php
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);
//var_dump($filtered);
$result = $filtered;

echo json_encode($result, JSON_UNESCAPED_UNICODE);
?>
Answers: