Sorting an array based on its value

后端 未结 2 891
耶瑟儿~
耶瑟儿~ 2021-01-15 20:09

I have an Array, Sample:

$array {
 [0] {
   [something]=1;
   [something2]=2;
     } 
 [1] {
   [something]=2;
   [something2]=4;
     }
 [2] {
   [somethin         


        
2条回答
  •  伪装坚强ぢ
    2021-01-15 20:53

    function compare($x, $y) {
        return $x['something'] - $y['something'];
    }
    
    usort($input_array, 'compare');
    

    you need to use a usort() similar to the above.

提交回复
热议问题