我有一个数组,当用户输入一个落入可用值的范围时,我想从中获取一系列数据。$dat= array("2020-02-01","2020-02-05","2020-02-10","20-02-12","2020-02-15");当用户输入 $start="2020-01-01" 和 $end="2020-02-07" 的搜索范围时我想让数组单独$dat生成$currentdat == array("2020-02-01","2020-02-05");
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
<?php
$dat= array("2020-02-01","2020-02-05","2020-02-10","20-02-12","2020-02-15");
//User input
$start ="2020-01-01";
$end="2020-02-07";
//Filter out dates between start and end date
$result = array_filter($dat, function($data_item) use($start,$end) {
return $data_item >= $start && $data_item <= $end;
});
$result会输出
Array
(
[0] => 2020-02-01
[1] => 2020-02-05
)
- 1 回答
- 0 关注
- 110 浏览
添加回答
举报
0/150
提交
取消