【发布时间】:2017-08-01 21:57:26
【问题描述】:
如何根据订单对 $item 类型进行排序?这是我目前拥有的:
$order = ['AA', 'zl', 'Dr', 'co', 'og'];
$items->sort(
function ($a, $b) use ($order) {
return strcmp($b->type, $a->type) // how do I apply the order here?
?: strcmp($b->date, $a->date);
}
);
基本上这是一个两列排序,首先按类型排序,然后按日期排序。该类型将使用数组顺序而不是典型的字母顺序进行排序。
【问题讨论】:
标签: php laravel collections