Laravel's array_sort helper DESC e ASC
arrays, laravel, laravel-4, php
Solution
The `array_sort()` helper function is a very thin wrapper around the default `Illuminate\Support\Collection::sortBy()` method. Excluding comments, this is all that it does:
function array_sort($array, Closure $callback)
{
return \Illuminate\Support\Collection::make($array)->sortBy($callback)->all();
}
While handy, it is limiting in its sorting capabilities. Similarly, the Collection class will allow you to change sort direction, but not much else.
In my opinion, you have two options:
Skip a Laravel-only solution and use some normal PHP and `array_multisort()`. As @Jon commented, there's some great details in this SO question.
Use a combination of grouping and sorting in a Collection object to achieve the results you want.
I'd just stick with #1.
Problem
I want to sort a multidimensionl array by one or more keys using the Laravel helper `array_sort`. ``` array( array('firstname_1','lastname_1'), array('firstname_2','lastnmae_2') ) ``` I want to order it first by firstname and then by lastname. I also want to do this in DESC or ASC order. How can I achieve this? There are functions aivalable in the internet to do this but I would like to understand how to use the Laravel helper. The doc for array_sort (http://laravel.com/docs/helpers#arrays) I don't find comprehensive.