php - Restructure array to be in descending date order -


i have multi-dimensional array, has index ['dates']. inside ['dates'] there index, , inside there ['date_time'] index data.

presently ordering of part of array oldest newest date/time. wish reverse first element most recent data.

here subset of data:

array(4) {   [0]=>array(3) {     ["id"]=>string(4) "1279"     ["name"]=>string(13) "account_name"     ["dates"]=>array(7) {       [0]=>array(3) {         ["date_time"]=>string(19) "2014-11-14 09:30:03"         ["follower_count"]=>string(4) "1567"         ["gains_losses"]=>string(4) "1567"       }       [1]=>array(3) {         ["date_time"]=>string(19) "2014-11-14 16:30:35"         ["follower_count"]=>string(4) "1566"         ["gains_losses"]=>string(2) "-1"       }... 

here full array

you might use date obj format instead of strtotime avoid suprises.

// comparison function function cmp($compare, $with) {     $a = $compare['date_time'];     $b = $with['date_time'];     if (strtotime($a) == strtotime($b)) {         return 0;     }     return ($a > $b) ? -1 : 1; }  foreach($your_arr &$item){     uasort($item['dates'], 'cmp'); } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -