Rumah > pembangunan bahagian belakang > tutorial php > 下部这些代码能不能简写啊

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

WBOY
Lepaskan: 2016-06-13 12:31:06
asal
778 orang telah melayarinya

下面这些代码能不能简写啊?
下面这段代码有没有简单办法实现啊,我觉得这样写太复杂了,如果写一个月的数据,岂不是需要写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 />
?>
Salin selepas log masuk

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan