1
如何根据订单对$ 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);
}
);
基本上它是一个两列的排序,它首先按类型排序,然后按日期排序。该类型将使用数组顺序而不是典型的字母顺序进行排序。
啊,你用过字典。这应该工作。 – rotaercz
完美的作品。谢谢 – rotaercz
不客气。 –