>  기사  >  백엔드 개발  >  下部这些代码能不能简写啊

下部这些代码能不能简写啊

WBOY
WBOY원래의
2016-06-13 12:31:06771검색

下面这些代码能不能简写啊?
下面这段代码有没有简单办法实现啊,我觉得这样写太复杂了,如果写一个月的数据,岂不是需要写30个case
求大侠帮忙,俺是新手

<?php<br />
date_default_timezone_set('PRC');<br />
$c1=0;<br />
$c2=0;<br />
$c3=0;<br />
$c4=0;<br />
$c5=0;<br />
$c6=0;<br />
$c7=0;<br />
$w = date("w",time());<br />
switch($w){<br />
	case 1: <br />
		<br />
		break; <br />
	case 2:<br />
	    $t1=strtotime(date("Y-m-d")." 23:59:59");//周二<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif(1387420136<=$t2){<br />
			$c2 += 1;<br />
		}<br />
		echo $c1;<br />
		break; <br />
	case 3:<br />
	    $t1=strtotime(date("Y-m-d")." 23:59:59");//周三<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周二<br />
		$t3=strtotime(date("Y-m-d",strtotime("-2 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif($t3<1387420136&&1387420136<=$t2){<br />
			$c2 += 1;<br />
		}elseif(1387420136<=$t3){<br />
			$c3 += 1;<br />
		}<br />
		echo $c1;		<br />
		break; <br />
	case 4:<br />
	    $t1=strtotime(date("Y-m-d")." 23:59:59");//周四<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周三<br />
		$t3=strtotime(date("Y-m-d",strtotime("-2 day"))." 23:59:59");//周二<br />
		$t4=strtotime(date("Y-m-d",strtotime("-3 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif($t3<1387420136&&1387420136<=$t2){<br />
			$c2 += 1;<br />
		}elseif($t4<1387420136&&1387420136<=$t3){<br />
			$c3 += 1;<br />
		}elseif(1387420136<=$t4){<br />
			$c4 += 1;<br />
		}<br />
		echo $c1;<br />
		break; <br />
	case 5:<br />
		$t1=strtotime(date("Y-m-d")." 23:59:59");//周五<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周四<br />
		$t3=strtotime(date("Y-m-d",strtotime("-2 day"))." 23:59:59");//周三<br />
		$t4=strtotime(date("Y-m-d",strtotime("-3 day"))." 23:59:59");//周二<br />
		$t5=strtotime(date("Y-m-d",strtotime("-4 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif($t3<1387420136&&1387420136<=$t2){<br />
			$c2 += 1;<br />
		}elseif($t4<1387420136&&1387420136<=$t3){<br />
			$c3 += 1;<br />
		}elseif($t5<1387420136&&1387420136<=$t4){<br />
			$c4 += 1;<br />
		}elseif(1387420136<=$t5){<br />
			$c5 += 1;<br />
		}<br />
		echo $c1;<br />
		break; <br />
	case 6:<br />
		$t1=strtotime(date("Y-m-d")." 23:59:59");//周六<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周五<br />
		$t3=strtotime(date("Y-m-d",strtotime("-2 day"))." 23:59:59");//周四<br />
		$t4=strtotime(date("Y-m-d",strtotime("-3 day"))." 23:59:59");//周三<br />
		$t5=strtotime(date("Y-m-d",strtotime("-4 day"))." 23:59:59");//周二<br />
		$t6=strtotime(date("Y-m-d",strtotime("-5 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif($t3<1387420136&&1387420136<=$t2){<br />
			$c2 += 1;<br />
		}elseif($t4<1387420136&&1387420136<=$t3){<br />
			$c3 += 1;<br />
		}elseif($t5<1387420136&&1387420136<=$t4){<br />
			$c4 += 1;<br />
		}elseif($t6<1387420136&&1387420136<=$t5){<br />
			$c5 += 1;<br />
		}elseif(1387420136<=$t6){<br />
			$c6 += 1;<br />
		}<br />
		echo $c1;<br />
		break; <br />
	case 7:<br />
	    $t1=strtotime(date("Y-m-d")." 23:59:59");//周日<br />
		$t2=strtotime(date("Y-m-d",strtotime("-1 day"))." 23:59:59");//周六<br />
		$t3=strtotime(date("Y-m-d",strtotime("-2 day"))." 23:59:59");//周五<br />
		$t4=strtotime(date("Y-m-d",strtotime("-3 day"))." 23:59:59");//周四<br />
		$t5=strtotime(date("Y-m-d",strtotime("-4 day"))." 23:59:59");//周三<br />
		$t6=strtotime(date("Y-m-d",strtotime("-5 day"))." 23:59:59");//周二<br />
		$t7=strtotime(date("Y-m-d",strtotime("-6 day"))." 23:59:59");//周一<br />
		if($t2<1387420136&&1387420136<=$t1){<br />
			$c1 += 1;<br />
		}elseif($t3<1387420136&&1387420136<=$t2){<br />
			$c2 += 1;<br />
		}elseif($t4<1387420136&&1387420136<=$t3){<br />
			$c3 += 1;<br />
		}elseif($t5<1387420136&&1387420136<=$t4){<br />
			$c4 += 1;<br />
		}elseif($t6<1387420136&&1387420136<=$t5){<br />
			$c5 += 1;<br />
		}elseif($t7<1387420136&&1387420136<=$t6){<br />
			$c6 += 1;<br />
		}elseif(1387420136<=$t7){<br />
			$c7 += 1;<br />
		}<br />
		echo $c1;<br />
		break;<br />
	default:;			    <br />
}<br />
?>

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.