我有这个数组的原始数据
['jan', 'feb', 'mar', 'may', 'june', 'dec']
我想将其转换为这样的数组组
[
0 => ['jan', 'feb', 'mar'],
1 => ['may', 'june'],
2 => ['dec'],
]
所以我想要的是对来自复选框的几个月的动态回报连续一个月进行分组
这是到目前为止我一直在尝试做的事情,现在被这个问题困扰了一段时间
if (count($trip_months) == 12):
$trip_months = 'ALL YEAR';
elseif (count($trip_months) > 0):
$temp_text = '';
$first_month = '';
$last_month = '';
$previous_month = '';
$next_month = '';
$separator = '';
$months = ['jan' => '', 'feb' => '', 'mar' => '', 'apr' => '', 'may' => '', 'june' => '', 'july' => '', 'aug' => '', 'sept' => '', 'oct' => '', 'nov' => '', 'dec' => ''];
foreach ($trip_months as $trip_month):
if ($trip_month != 'jan') $previous_month = $months[$trip_month];
if ($trip_month != 'dec') $next_month = $months[$trip_month];
if ($first_month == '') {
$first_month = $trip_month;
$last_month = $trip_month;
} else {
}
endforeach;
$trip_months = $temp_text;
endif;
我想我并没有尽我所能实现的目标
$a = ['jan', 'feb', 'mar', 'may', 'june', 'dec'];
$b = ['jan', 'feb', 'mar', 'apr', 'may', 'june', 'jule', 'aug', 'sep', 'oct', 'nov', 'dec'];
$c = [];
$i = 0;
$re = false;
foreach($b as $m) {
if(in_array($m, $a)) {
$c[$i][] = $m;
$re = true;
} elseif($re) {
$i++;
$re = false;
}
}
var_dump($c);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句