所有订单的日期,有序描述

Dates of all Orders , ordered desc

我想按降序排列所有订单的日期。对于每个用户,我正在考虑使用 orderBy,目前我只返回所有日期。我想知道这是否可能。因为我没有使用查询

注意:我现在做的 orderby 行不起作用

 foreach($users as $user)
  {

    foreach ($orders as $order) {
     if($order->getCustomer()->getId() == $user->getId()){

        $orderDates = $order->getDate();
        $ordered = $orderDates->orderBy('date' ,'DESC');

     }
    }

你可以使用 usort cf php doc

function cmp($a, $b)
{
  $ad = new DateTime($a);
  $bd = new DateTime($b);

  if ($ad == $bd) {
    return 0;
  }

  return $ad < $bd ? -1 : 1;
}

然后在你的代码中:

usort($orderDates, "cmp");