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

WBOY
Release: 2016-06-13 11:42:58
Original
791 people have browsed it

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template