我的排序功能一直很好。根据属性将集合排序为特定顺序。现在我已被要求(也尽可能)按字母顺序排序。
我有2个静态数组,提供2个当前属性的顺序。目前,它按部分命令收集,然后逐个季度。
我想要添加的是按季节分组的项目按字母顺序排序。如果这是有道理的。
$mp = $mp->sort(function ($a, $b) use ($order, $subOrder) {
$pos_a = array_search($a->section, $order);
$pos_b = array_search($b->section, $order);
if ($pos_a != $pos_b) {
return $pos_a - $pos_b;
}
$pos_a2 = array_search($a->season, $subOrder);
$pos_b2 = array_search($b->season, $subOrder);
if ($pos_a2 != $pos_b2) {
return $pos_a2 - $pos_b2;
}
return 0;
});
除了编写一个静态的A-> Z数组并将该array_search添加到我正在努力寻找一种很好的方法之外。我试过简单地命令原始查询,但我当前的排序函数似乎不尊重字母查询。
真的很感激任何正确方向的推动!
干杯