I have an array of date like
a[0]=>2013-10-05
a[1]=>2013-10-25
a[2]=>2013-10-15
a[3]=>2013-10-28
I want to sort in ascending order. How can i sort this?
I have an array of date like
a[0]=>2013-10-05
a[1]=>2013-10-25
a[2]=>2013-10-15
a[3]=>2013-10-28
I want to sort in ascending order. How can i sort this?
Try this;
$orderByDate = $my2 = array();
foreach($data as $key=>$row)
{
$my2 = explode('-',$row[1]);
$my_date2 = $my2[1].'-'.$my2[0].'-'.$my2[2];
$orderByDate[$key] = strtotime($my_date2);
}
array_multisort($orderByDate, SORT_ASC, $data);
Try the default sort function as stated here: Sort by Date
Or use a custom sort function like suggested here: Custom Search Function
function sortFunction( $a, $b )
{
//$a and $b are two values from your array
//Return a value > 0 then $a is greater than $b
return strtotime($a) - strtotime($b);
}
usort($data, "sortFunction");