Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个日期数组
a[0]=>2013-10-05 a[1]=>2013-10-25 a[2]=>2013-10-15 a[3]=>2013-10-28
我想按升序排序。我该如何排序?
试试这个;
$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);
尝试此处所述的默认排序功能:按日期排序
或使用此处建议的自定义排序功能:自定义搜索功能
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");