【发布时间】:2020-01-21 18:49:56
【问题描述】:
我已经为此苦苦挣扎了一段时间,所以我决定寻求帮助。
我需要像这样转换日期列表:
2019-09-17,
2019-09-16,
2018-08-15,
2017-08-14
并将它们输出为唯一年/月/日的嵌套列表:
- 2019
- 09
- 17
- 16
- 09
- 2018
- 08
- 15
- 08
- 2017
- 08
- 14
- 08
$dates = wp_list_pluck( $queriedFiles->posts, 'post_date' );
$cleanDates = array();
foreach ($dates as $date) {
$createDate = new DateTime($date);
$date = $createDate->format('Y-m-d');
array_push($cleanDates, $date);
}
$uniqueDates = array_unique($cleanDates);
$years = array();
$properDates = array();
foreach ($uniqueDates as $date) {
$createDate = new DateTime($date);
$strippedYear = $createDate->format('Y');
$strippedMonth = $createDate->format('m');
$strippedDay = $createDate->format('d');
$thisDate = array('year' => $strippedYear, 'month'=>$strippedMonth, 'day'=>$strippedDay);
array_push($years, $strippedYear);
array_push($properDates, $thisDate);
}
我希望最终得到一个多维数组,我可以通过循环获得年/月/日
你们能提供的任何帮助都会很棒。谢谢!
【问题讨论】:
标签: php wordpress sorting date datetime