php - Sort Array Date wise if given at Zero index Key -


actually have 1 array , need sort according date wise unfortunately becomes difficult me. can me out ...

i have array in below

         $data = array (              array('july 2015', 2 , 5, 0, ''),             array('september 2015', 2 , 5, 0, ''),             array('august 2015', 2 , 5, 0, ''),             array('march 2017', 2 , 5, 0, ''),             array('december 2015', 2 , 5, 0, ''),             array('march 2016', 2 , 5, 0, ''),          ); 

now want sort array according date wise start smallest date bigger date like, becomes that.

         $data = array (              array('july 2015', 2 , 5, 0, ''),             array('august 2015', 2 , 5, 0, ''),             array('september 2015', 2 , 5, 0, ''),             array('december 2015', 2 , 5, 0, ''),             array('march 2016', 2 , 5, 0, ''),             array('march 2017', 2 , 5, 0, ''),          ); 

can me.

any appreciated.

thanks

$data = array(     array('july 2015', 2, 5, 0, ''),     array('september 2015', 2, 5, 0, ''),     array('august 2015', 2, 5, 0, ''),     array('march 2017', 2, 5, 0, ''),     array('december 2015', 2, 5, 0, ''),     array('march 2016', 2, 5, 0, ''), );  uasort($data, function($a,$b){      if(strtotime($a[0]) == strtotime($b[0]))      {          return 0;     }      return strtotime($a[0]) < strtotime($b[0]) ? -1 : 1;  });  print_r($data); 

or simplest way deceze said

uasort($data, function($a,$b){     return strtotime($a[0]) - strtotime($b[0]); }); 

demo

demo suggested deceze


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -