0

I have an array which I am getting from an API call. The array looks like this :

  [3] => Array
        (
            [project_id] => project:eead2382e9d679814c13c77ab857ae53
            [start_date] => 2017-01-16
            [end_date] => 2019-11-15
        )

    [4] => Array
        (
            [project_id] => project:096b2fc2bc5133784c13c77ab857ae53
            [start_date] => 2017-03-08
            [end_date] => 2017-06-30
        )

I am looping through all my results and checking if the end_date value equals today or if it is greater than today. Like this :

$today = date("Y-m-d");

$qualified = [];

foreach($results as $result) {
    if($result['end_date'] > $today){
        array_push($qualified, $result);
    }
}

echo '<pre>';
print_r($qualified);
echo $today;

Yet i get an empty array eventho there are values greater than today. Am I doing something wrong?

Kevin.a
  • 4,094
  • 8
  • 46
  • 82
  • looks fine to me. are you sure `$result['end_date']` is set and actually greater than today? – Horen Nov 05 '19 at 12:37
  • http://sandbox.onlinephpfunctions.com/code/cd4a1337bd04f85f7bd497073a3d8a6cc3478a99 – Horen Nov 05 '19 at 12:40
  • @Horen I made a mistake, the array format i was getting is different than what my code assumes. Instead of getting single arrays i get one huge array somehow. I know how to fix it tho, sorry for that – Kevin.a Nov 05 '19 at 12:41

0 Answers0