我有一系列日期,我想知道是否有可能搜索数组并删除今天之前的所有项目,并保留其余部分?
这是我的数组
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
)
)
答案 0 :(得分:2)
类似的东西:
$buffer = array();
foreach ($dates as $element) {
if (strtotime($element['date']) >= time()) {
$buffer[] = $element;
}
}
答案 1 :(得分:1)
如何循环并将日期与实际所需数据进行比较并构建新的过滤数组?
$newarray = array();
foraeach($array as $data)
{
if($data['date'] >= $yourdate)
{
$newarray] = $data;
}
}
答案 2 :(得分:0)
array_walk
function允许您定义一个回调以在数组中的每个项目上运行。