gpt4 book ai didi

php - 对返回新数组的 php 数组进行排序

转载 作者:可可西里 更新时间:2023-11-01 12:35:36 31 4
gpt4 key购买 nike

我正在寻找一种可靠的标准方法来排序数组,返回排序(关联)数组作为返回值

我读过的所有 PHP.net 函数都返回 BOOLEAN 值,或 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 )

无需处理字符串,只需处理 INT-s。

最佳答案

这是一个单行:

call_user_func(function(array $a){asort($a);return $a;}, $some_mixed_array);

关于php - 对返回新数组的 php 数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18720682/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com