Sort array of objects by date field

后端 未结 4 1978
天涯浪人
天涯浪人 2021-01-01 15:57

How can I re-arrange a array of objects like this:

 [495] => stdClass Object
        (
         [date] => 2009-10-31 18:24:09
         ...
        )
 [         


        
4条回答
  •  旧巷少年郎
    2021-01-01 16:25

    I wanted to expand on arnaud576875 and Michael Irigoyen.

    Same issue with object containing dateTime with Symphony.

    I coudn't use $a['date'] because it was not an key array.

    usort($verifications, function($a, $b) {
       return $a->getDate()->format('U') - $b->getDate()->format('U');
    });
    

    This solved my problem

提交回复
热议问题