我有一个日期数组,我想知道是否可以搜索数组并删除今天日期之前的任何项目,并保留其余部分?
这是我的数组Array
(
[0] => Array
(
[date] => 2013-07-14
)
[1] => Array
(
[date] => 2013-08-31
)
[2] => Array
(
[date] => 2013-09-15
)
[3] => Array
(
[date] => 2013-10-12
)
[4] => Array
(
[date] => 2013-10-16
)
[5] => Array
(
[date] => 2013-10-19
)
[6] => Array
(
[date] => 2013-10-23
)
[7] => Array
(
[date] => 2013-10-26
)
[8] => Array
(
[date] => 2013-10-30
)
[9] => Array
(
[date] => 2013-09-07
)
[10] => Array
(
[date] => 2013-08-14
)
[11] => Array
(
[date] => 2013-08-24
)
[12] => Array
(
[date] => 2013-09-11
)
[13] => Array
(
[date] => 2013-09-28
)
[14] => Array
(
[date] => 2013-10-05
)
)
像这样:
$buffer = array();
foreach ($dates as $element) {
if (strtotime($element['date']) >= time()) {
$buffer[] = $element;
}
}
如何循环遍历和比较日期与实际需要的数据,并构建一个新的过滤数组?
$newarray = array();
foraeach($array as $data)
{
if($data['date'] >= $yourdate)
{
$newarray] = $data;
}
}
array_walk
函数允许您定义一个回调函数来运行在数组中的每个项上。