Reputation: 211
Is there a shorter way to write this code?
uasort($my_array, function ($a, $b) {
if ($a['number'] == $b['number'])
return 0;
elseif ($a['number'] < $b['number'])
return 1;
else
return -1;
});
This works, but I need to repeat this code many times.
Is there a better way to do it?
Specifically is there a better way to do it in Laravel?
Upvotes: 0
Views: 83
Reputation: 219938
You can use a Laravel collection if you want:
$my_array = collect($my_array)->sortBy('number')->all();
Upvotes: 2