PHP的本地排序函数会通过引用进行修改,并且不会返回排序后的数组。
我正在寻找一种可靠的标准方法来对数组进行排序,并将排序后的数组作为返回值返回。
我阅读过的所有PHP.net函数都返回布尔值或0-1。
我需要的方法应该是这样的:
$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 )
无需处理字符串,只需处理整数。
function custom_sort($a) { sort($a); return $a; }
- knittlassert(sort(array_keys($myData)) == array('x','y'))
,但它会报错:"Only variables should be passed by reference"。 - Darren Cook