Php 阵列滤波器
我将日期存储在mysql数据库中的日期字段中,如下所示Php 阵列滤波器,php,arrays,Php,Arrays,我将日期存储在mysql数据库中的日期字段中,如下所示 09/03/2018|29/03/2018|17/06/2018|10/07/2018|28/10/2019|12/02/2019 在php中,我将上述日期格式转换为数组 $currentyear= date("Y"); $this_month = array(); $other_month = array(); $dates_list = @explode("|", $dates_list); $dates_list = str_r
09/03/2018|29/03/2018|17/06/2018|10/07/2018|28/10/2019|12/02/2019
在php中,我将上述日期格式转换为数组
$currentyear= date("Y");
$this_month = array();
$other_month = array();
$dates_list = @explode("|", $dates_list);
$dates_list = str_replace(array("\r", "\n"), '', $dates_list);
foreach($dates_list as $date)
{
if(strstr($date,$month))
{
array_push($this_month,$date);
} else {
array_push($other_month,$date);
}
}
这是我希望筛选的$other_month数组
因此,在以下数组中09/03/2018 | 29/03/2018 | 17/06/2018 | 10/07/2018 | 28/10/2019 | 12/02/2019
仅显示最后两个日期
我想过滤掉所有没有“本年度”的日期,如果有人能帮忙,我将不胜感激
谢谢你我并不喜欢你在DB方面所做的事情,但是要过滤你的数组,这里有一个脚本:
$this_year = [];
$other_years = [];
foreach ($dates_list as $date) {
if (date('Y', strtotime($date)) == date('Y')) {
$this_year[] = $date;
} else {
$other_years[] = $date;
}
}
如果您将日期以json语法存储在数据库的文本字段中会更好。是的,我同意,这是一个旧的继承系统,除了这个小问题之外,所有方面都可以处理。因此,为了避免重写我想在这里问的整个事情谢谢你的时间,我同意这不是最好的程序,但这是我目前必须处理的,我尝试了上述方法,但遗憾的是没有成功me@Tilly尝试后,每个数组中的值是什么?