我有这个简单的循环,它输出一个非多维数组:
foreach($api->parse($_GET['start'], $_GET['finish']) as $item){
$purl = parse_url($item->url());
$data[] = array(
'url' => $purl,
'publish' => $item->parse_date('j M Y, g:i a'),
'category' => htmlentities($item->cat()),
'status' => '0',
);
array_push($data);
}
var_dump($data);
如何从上面获得最早和最新 publish
日期。请注意,publish
格式为14 Jan 2014, 7:00 am
等。
将进一步使用日期在数据库中进行选择:
$query_items = "SELECT * FROM `categories` WHERE
date BETWEEN 'EARLIEST_DATE_IN_ARRAY' AND 'LATEST_DATE_IN_ARRAY' ";
答案 0 :(得分:3)
未测试
usort($data, function($a, $b) {
$date1 = DateTime::createFromFormat('j M Y, G:i a', $a);
$date2 = DateTime::createFromFormat('j M Y, G:i a', $b);
return $date1 > $date2;
});
$first = array_shift($data);
$last = array_pop($data);
答案 1 :(得分:0)
这是我从John Conde未经测试的回答中得出的结论:
usort($data, function ($a, $b) {
$date1 = (DateTime::createFromFormat('j M Y, g:i a', $a));
$date2 = (DateTime::createFromFormat('j M Y, g:i a', $b));
return $date2 > $date1;
});
$first = array_shift($data);
$last = array_pop($data);
$first = (new DateTime($first["publish"]))->modify('-1 day')->format('m-d-Y');
$last = (new DateTime($last["publish"]))->modify('-1 day')->format('Y-m-d H:i:s');