2
我正在使用Laravel 5.4,我正在使用一個集合。Laravel集合從低到高
這是我收集:
[
{
"km": 38.453608974709326,
"location": "Store1"
},
{
"km": 72.90179157108496,
"location": "Store2"
},
{
"km": 185.31643523106044,
"location": "Store3"
},
{
"km": 182.8661179764287,
"location": "Store4"
},
{
"km": 199.5931242065379,
"location": "Store5"
},
{
"km": 117.33173807712892,
"location": "Store6"
},
{
"km": 156.86414686427264,
"location": "Store7"
},
{
"km": 148.73811818717547,
"location": "Store8"
}
]
如何訂購從最低公里的最高的?已經嘗試過這一點,但它不工作:
$items->sortByDesc(function ($item, $key) {
return $item['km'];
});
非常感謝