我有以下代码。我有一个月的数组。
$m="";
$months = array(1=>'January',2=>'February',3=>'March',4=>'April',5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',10=>'October',11=>'November',12=>'December');
foreach($objhst_fees->fetch_hst_fees("`month`,`fees`","where `grno`='".$stu_name['grno']."'")as $count_month)
{
//value like:$count_month['month']=1,2,3
$m .= $count_month['month'].",";
}
所以假设 $m=1,2,3,4,5,
然后,我将其分解并创建数组。
$paid_month = explode(",",$m);
$arr=array();
foreach($paid_month as $key=>$p)
{
array_push($arr,$p);
}
然后,我打印不在$arr
.
foreach($months as $key=>$a)
{
if(!in_array($key,$arr))
{
echo $a.",";
//echo $months[$key];
}
}
但我认为,这种方法是渴望它。那么这样做的替代方法是什么?