[英]Find sort and seperate an array of date in year in month in php
I have an array of dates like this: 我有这样一个日期数组:
Array
(
[0] => 10-19-2016
[1] => 10-29-2016
[2] => 11-08-2016
[3] => 11-18-2016
[4] => 11-28-2016
[5] => 12-08-2016
[6] => 12-18-2016
[7] => 12-28-2016
[8] => 01-07-2017
[9] => 01-17-2017
[10] => 01-27-2017
[11] => 02-06-2017
[12] => 02-16-2017
[13] => 02-18-2017
[14] => 02-26-2017
[15] => 03-08-2017
[16] => 03-18-2017
[17] => 03-28-2017
[18] => 03-30-2017
[19] => 04-07-2017
[20] => 04-09-2017
)
How can I sort and separate them into year, month and day so that it will look like the following? 如何将它们分类并分成年,月和日,使其看起来像以下内容?
2016 oct 19,20 nov 08,18,28... 2017 jan 07,17
$result_arr=[];
$date_arr=array("10-19-2016","10-29-2016","11-08-2016","11-28-2016");
foreach($date_arr as $date)
{
$date_arr=explode("-",$date);
$act_date=$date_arr[1]."-".$date_arr[0]."-".$date_arr[2];
$result_arr[strtotime($act_date)]=date("Y M d",strtotime($act_date));
}
ksort($result_arr);
echo "<pre>";
print_r($result_arr);
Hope it will help 希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.