Sort a php array returning new array

后端 未结 3 2108
离开以前
离开以前 2021-01-04 06:39

I am looking for a reliable standard method to sort an array, returning the sorted ( associative ) array, as return value.

All the

3条回答
  •  执笔经年
    2021-01-04 06:58

    As others have said, your best bet is to create a custom function. However, in order to maintain flexibility with the future of PHP, I would use a variadic function. Essentially, you set your function to accepts whatever parameters are passed to it, and pass them through to the actual sort() function. Done this way, you can use whatever optional parameters exist for the standard function you're putting the wrapper around -- even if those parameters change in the future.

    function mysort( ...$params ) {
        sort( ...$params );
        return $params[0];
    }
    

提交回复
热议问题