我有一个多维数组,需要根据datetime字段是否在某个日期范围之间从其中提取数据。
datetime列是unix时间戳。
我已经知道如何根据日期对数组进行排序,但是现在我想只返回数组的一部分,如果datetime字段来自某个月份或某个年份。
密钥需要保存。
数组的例子:
<?
$videoids = array(
'iD-7H6Rv-SM' => array
(
'datetime' => '1421693217',
'title' => 'title',
'description' => 'description',
'channel' => 'info',
'url' => 'url'
),
'X9tzt0MEIRI' => array
(
'datetime' => '1422784090',
'title' => 'title',
'description' => 'description',
'channel' => 'info',
'url' => 'url'
),
'TaFgrY9HsUA' => array
(
'datetime' => '1418712579',
'title' => 'title',
'description' => 'description',
'channel' => 'info',
'url' => 'url'
),
'i9PGMYb7Aoc' => array
(
'datetime' => '1404178390',
'title' => 'title',
'description' => 'description',
'channel' => 'info',
'url' => 'url'
),
);?>
前两个内部数组datetime字段来自2015年
最后两个内部数组datetime字段来自2014
我如何提取只有内部数组包含一个时间戳与年2014?
我想从数组中按年显示数据,甚至可能按月分解。
的例子:
click here to display data from 2015
click here to display data from January
before year:
$search_year = 2015; // $_REQUEST['year']
foreach ($videoids AS $video) {
if(@date('Y', $video['datetime']) == $search_year) {
echo '<pre>' . print_r($video, true) . '</pre>';
}
}
http://php.net/manual/en/function.date.php