I am looking for a reliable standard method to sort an array, returning the sorted ( associative ) array, as return value.
All 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.
Return Value: It returns a boolean value, TRUE on success and False in failure. It sorts the original array in ascending order which is passed as a parameter.
php function sortArray() { $inputArray = array(8, 2, 7, 4, 5); $outArray = array(); for($x=1; $x<=100; $x++) { if (in_array($x, $inputArray)) { array_push($outArray, $x); } } return $outArray; } $sortArray = sortArray(); foreach ($sortArray as $value) { echo $value . "<br />"; } ?>
Here's a one-liner:
call_user_func(function(array $a){asort($a);return $a;}, $some_mixed_array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With