If you have an array of dates you wish to place in order ‘usort’ will work for you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $myarray=array(0=>'20-05-2018',1=>'02-01-2018',2=>'30-03-2018'); usort($myarray, function($a, $b) { $dateTimestamp1 = strtotime($a); $dateTimestamp2 = strtotime($b); return $dateTimestamp1 < $dateTimestamp2 ? -1: 1; }); echo 'Min: ' . $myarray[0]; echo '<br/>'; echo 'Max: ' . $myarray[count($date_arr) - 1]; ?> |