inmarelibero/Twig — comment on commit 57c6193506e3b86bf615c57ce561e3cf9dc56910
File:  line 0
By inmarelibero:

btw, I propose a different implementation. there is no real need to use the uasort() function; I just create a temp array copying the original one, but substituting the original values with the ones to sort.

for example, the original array is:

$array[0] = array('id' => 1, 'firstname' => 'Dan', 'lastname' => 'Abbnet');
$array[1] = array('id' => 2, 'firstname' => 'Jerry', 'lastname' => '2Ahem');
$array[2] = array('id' => 3, 'firstname' => 'bruno', 'lastname' => 'albarello');
$array['Adani'] = array('id' => 4, 'firstname' => '3Lino', 'lastname' => 'Adani');
$array[4] = array('id' => 5, 'firstname' => 'Woody', 'lastname' => 'Allen');
$array[5] = array('id' => 6, 'firstname' => 'Allen', 'lastname' => 'Adler');

while I sort by "lastname", the sorting array is:

$arrToSort[0] = array('Abbnet');
$arrToSort[1] = array('2Ahem');
$arrToSort[2] = array('albarello');
$arrToSort['Adani'] = array('Adani');
$arrToSort[4] = array('Allen');
$arrToSort[5] = array('Adler');

it operates the sorting, then replaces the values of $arrToSort with the original ones taken from $array and returns $arrToSort.

I have some doubts on the elegance of this method but it should work fine, any suggestions?