php - How to sorting multi array by value data? -


how sorting multi array value ? have data this

$num_a = $_post['num_a']; //get value data array num_a[] $num_b = $_post['num_b']; //get value data array num_b[] $score = $_post['score']; //get value data array socre[]  ($i=0; $i < count($num_a); $i++) {      //set total data num_a , num_b value score     $ring[($num_a[$i])][($num_b[$i])] = $score[$i];  }  print_r($ring); //output  array (     [0] => array         (             [1] => 5         )     [1] => array         (             [2] => 1         )     [2] => array         (             [0] => 3         ) ) 

how display results sorted desc, results this, thank you

the output want

print_r($ring);

array (     [0] => array         (             [1] => 5         )     [2] => array         (             [0] => 3         )     [1] => array         (             [2] => 1         ) ) 

you can use array_multisort (php 4, php 5)

array_multisort(                  array_map(function($_){return reset($_);},$ring),                   sort_desc,                   $ring                ); 

test

[akshay@localhost tmp]$ cat test.php  <?php  $data = array(    array( 1 => 5),    array( 2 => 1),    array( 0 => 3),         );  // input print_r($data);  // sort desc array_multisort(array_map(function($_){return reset($_);},$data), sort_desc, $data);   // output - sorted array print_r($data);  ?> 

output

[akshay@localhost tmp]$ php test.php  array (     [0] => array         (             [1] => 5         )      [1] => array         (             [2] => 1         )      [2] => array         (             [0] => 3         )  ) array (     [0] => array         (             [1] => 5         )      [1] => array         (             [0] => 3         )      [2] => array         (             [2] => 1         )  ) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -