猿问

如何将日期范围拆分为具有用户输入的特定数组的数组?

我有一个数组,当用户输入一个落入可用值的范围时,我想从中获取一系列数据。

$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");


慕标琳琳
浏览 111回答 1
1回答

烙印99

<?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) {&nbsp; &nbsp; return $data_item >= $start && $data_item <= $end;});$result会输出Array(&nbsp; &nbsp; [0] => 2020-02-01&nbsp; &nbsp; [1] => 2020-02-05)
随时随地看视频慕课网APP
我要回答