Sort a php array returning new array

后端 未结 3 2110
离开以前
离开以前 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 07:05

    Would you be able to do this?

    $some_mixed_array = array( 998, 6, 430 );
    function custom_sort( $array )
    {
      // Sort it
      asort($array);
    
      // return sorted array
      return $array;
    }
    
    custom_sort( $some_mixed_array );
    
    // returning: array( 6, 430, 998 )
    

    This would also solve your issue:

    $some_mixed_array = array( 998, 6, 430 );
    echo '
    '.print_r($some_mixed_array, true).'
    '; asort($some_mixed_array); // <- BAM! // returning: array( 6, 430, 998 ) echo '
    '.print_r($some_mixed_array, true).'
    ';

提交回复
热议问题