PHP CURL Array filter - Date Variable

Viewed 727
<?php

    $today = date("y-m-d");
    $filter = ['2019-06-18'];

    // Api Request
    $a = ordersRequest("statistics/list", array("idapp" => 11111));

    $links = $a['statistics']['grp_date'];
    $filtered = array_filter($links, function ($item) use ($filter) {
    return in_array($item['date'], $filter);
    });
    print_r($filtered);

     ?>

This Works:

$filter = ['2019-06-02'];

But how can i get the current date in this variable?

$filter = ['$today'];
$filter = [$today];
$filter = date("y-m-d");

Don't works for me

1 Answers
$filter = date("y-m-d");

is not the same as

$filter = ['2019-06-02'];

for 2 reasons.

  1. [] makes an array, date() returns a string.
  2. y is a two digit representation of the year. Y should be used for the 4 digit representation.

    $filter = [date('Y-m-d')];
    
Related