如何区分日期列表中的日期?的PHP

我一直在尝试列出上学和不上学的日子.

在这里闲逛.另一个数组包含我没上学的日子.

<?PHP
$fecha1 = "2015-03-10";
$fecha2 = date("Y-m-d",strtotime($fecha1."+ 10 days"));
$fecha3 = array("2015-03-11","2015-03-14","2015-03-17");
$j=1;

for($i=$fecha1;$i<$fecha2;$i = date("Y-m-d", strtotime($i ."+ 1 days"))){
    for ($n=0; $n <count($fecha3) ; $n++) { 
        if($i==$fecha3[$n]){
            $obs="not there";

        }else{
            $obs="there";       
        }
    }   
    echo "Day ".$j." ".$i."---".$obs."<br />";
    $j++;
}
?>

输出

Day 1 2015-03-10---there
Day 2 2015-03-11---there
Day 3 2015-03-12---there
Day 4 2015-03-13---there
Day 5 2015-03-14---there
Day 6 2015-03-15---there
Day 7 2015-03-16---there
Day 8 2015-03-17---not there
Day 9 2015-03-18---there
Day 10 2015-03-19---there

我不明白为什么它在第二天不说“不在那里” 2015-03-11
2015年5月5日,第5天,有人帮助我,我已经使用了几个小时.

解决方法:

找到针后,您应该添加一个中断:

if($i==$fecha3[$n]){
        $obs="not there";
        break; // this is important
    }else{
        $obs="there";
    }

另一种选择是in_array(),用于搜索

if(in_array($i, $fecha3)){
    $obs="not there";
}else{
    $obs="there";
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...