Sort multidimensional array


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.