Reputation: 634
I want to sort the Dates of all orders, in a descending list. for each user, I was thinking of using orderBy, currently I am only returning all dates. I was wondering if this is possible. Since I am not doing it using a query
NOTE: I do now the orderby line doesn't work
foreach($users as $user)
{
foreach ($orders as $order) {
if($order->getCustomer()->getId() == $user->getId()){
$orderDates = $order->getDate();
$ordered = $orderDates->orderBy('date' ,'DESC');
}
}
Upvotes: 1
Views: 78
Reputation: 722
you can use 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;
}
Then in your code :
usort($orderDates, "cmp");
Upvotes: 0