Posted By

bitsculptor on 02/11/12


Tagged

php sort array multidimensional


Versions (?)

Sort multidimensional array


 / Published in: PHP
 

This sorts a multi-dimensional array by one of the values in the array. Sorts in Desc order (most recent date first).

  1. <?php
  2. $transactions = array(
  3. 0 => array('date'=>1324235252, 'day'=>'monday'),
  4. 1 => array('date'=>1326516552, 'day'=>'tuesday'),
  5. 2 => array('date'=>1333453235, 'day'=>'wednesday')
  6. )
  7.  
  8. function sortByOrder($a, $b) {
  9. return $b['date'] - $a['date'];
  10. }
  11.  
  12. usort($transactions, 'sortByOrder');

Report this snippet  

You need to login to post a comment.