Sort array by value and store in variable

前端 未结 3 474
故里飘歌
故里飘歌 2021-01-18 21:09
$array = array(5,4,6,8,5,3,4,6,1);

I want to sort $array like asort does, but the problem is that asort is a

相关标签:
3条回答
  • 2021-01-18 21:24

    Do this for maintaining $array in its original order

    $array = array(5,4,6,8,5,3,4,6,1);
    $sorted_array = $array;
    asort($sorted_array);
    

    Output

    http://codepad.viper-7.com/8E78Fo

    0 讨论(0)
  • 2021-01-18 21:36
     $orignal_array = array(5,4,6,8,5,3,4,6,1);
     $copied_array = $orignal_array;
    
     asort($copied_array);
     $sorted_array = $copied_array;
    
     not the most efficient way to do it though :(
    
    0 讨论(0)
  • 2021-01-18 21:37

    Sort it first and then assign it

    asort($array);
    $sorted_array = $array
    
    0 讨论(0)
提交回复
热议问题