Sorting an array based on its value

后端 未结 2 890
耶瑟儿~
耶瑟儿~ 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.

    0 讨论(0)
  • 2021-01-15 21:04

    Would the following suffice?

    foreach($array as $key => $value){
        ksort( $array[$key] );
    }
    
    0 讨论(0)
提交回复
热议问题