PHP's native sorting functions modify by reference and do not return the sorted array.
I am looking for a reliable standard method to sort an array, returning the sorted array as the return value.
All of the PHP.net functions I have read about return BOOLEAN value, or 0-1.
The method I need would be something like:
$some_mixed_array = array( 998, 6, 430 );
function custom_sort( $array )
{
// Sort it
// return sorted array
}
custom_sort( $some_mixed_array );
// returning: array( 6, 430, 998 )
No need to handle strings, just INT-s.
function custom_sort($a) { sort($a); return $a; }
– Espousefunction custom_short($array) { asort($array); return $array }
this one? – Conferenceshort
– Continuantsort(), asort(), ksort(), etc
functions actually alter the array that you pass to them, so you can simply return the exact same array after it's been sorted. – Belovedassert(sort(array_keys($myData)) == array('x','y'))
This fails with "Only variables should be passed by reference". – Weigand