The lower part of the code can be shortened.

Source: Internet
Author: User
The following code can be abbreviated AH?
The following code is not a simple way to achieve ah, I think this is too complicated to write, if you write one months of data, it is not necessary to write 30 case
I'm a novice, I beg the hero's help
 Date_default_timezone_set (' PRC ');
$c 1=0;
$c 2=0;
$c 3=0;
$c 4=0;
$c 5=0;
$c 6=0;
$c 7=0;
$w = Date ("W", Time ());
Switch ($w) {
Case 1:

Break
Case 2:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Tuesday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif (1387420136<= $t 2) {
$c 2 + = 1;
}
echo $c 1;
Break
Case 3:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Wednesday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Tuesday
$t 3=strtotime (Date ("Y-m-d", Strtotime ("2 Day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif ($t 3<1387420136&&1387420136<= $t 2) {
$c 2 + = 1;
}elseif (1387420136<= $t 3) {
$c 3 + = 1;
}
echo $c 1;
Break
Case 4:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Thursday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Wednesday
$t 3=strtotime (Date ("Y-m-d", Strtotime ("2 Day")). " 23:59:59 ");//Tuesday
$t 4=strtotime (Date ("Y-m-d", Strtotime ("3 Day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif ($t 3<1387420136&&1387420136<= $t 2) {
$c 2 + = 1;
}elseif ($t 4<1387420136&&1387420136<= $t 3) {
$c 3 + = 1;
}elseif (1387420136<= $t 4) {
$c 4 + = 1;
}
echo $c 1;
Break
Case 5:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Friday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Thursday
$t 3=strtotime (Date ("Y-m-d", Strtotime ("2 Day")). " 23:59:59 ");//Wednesday
$t 4=strtotime (Date ("Y-m-d", Strtotime ("3 Day")). " 23:59:59 ");//Tuesday
$t 5=strtotime (Date ("Y-m-d", Strtotime ("4 Day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif ($t 3<1387420136&&1387420136<= $t 2) {
$c 2 + = 1;
}elseif ($t 4<1387420136&&1387420136<= $t 3) {
$c 3 + = 1;
}elseif ($t 5<1387420136&&1387420136<= $t 4) {
$c 4 + = 1;
}elseif (1387420136<= $t 5) {
$c 5 + = 1;
}
echo $c 1;
Break
Case 6:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Saturday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Friday
$t 3=strtotime (Date ("Y-m-d", Strtotime ("2 Day")). " 23:59:59 ");//Thursday
$t 4=strtotime (Date ("Y-m-d", Strtotime ("3 Day")). " 23:59:59 ");//Wednesday
$t 5=strtotime (Date ("Y-m-d", Strtotime ("4 Day")). " 23:59:59 ");//Tuesday
$t 6=strtotime (Date ("Y-m-d", Strtotime ("5 Day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif ($t 3<1387420136&&1387420136<= $t 2) {
$c 2 + = 1;
}elseif ($t 4<1387420136&&1387420136<= $t 3) {
$c 3 + = 1;
}elseif ($t 5<1387420136&&1387420136<= $t 4) {
$c 4 + = 1;
}elseif ($t 6<1387420136&&1387420136<= $t 5) {
$c 5 + = 1;
}elseif (1387420136<= $t 6) {
$c 6 + = 1;
}
echo $c 1;
Break
Case 7:
$t 1=strtotime (Date ("y-m-d"). " 23:59:59 ");//Sunday
$t 2=strtotime (Date ("Y-m-d", Strtotime ("1 day")). " 23:59:59 ");//Saturday
$t 3=strtotime (Date ("Y-m-d", Strtotime ("2 Day")). " 23:59:59 ");//Friday
$t 4=strtotime (Date ("Y-m-d", Strtotime ("3 Day")). " 23:59:59 ");//Thursday
$t 5=strtotime (Date ("Y-m-d", Strtotime ("4 Day")). " 23:59:59 ");//Wednesday
$t 6=strtotime (Date ("Y-m-d", Strtotime ("5 Day")). " 23:59:59 ");//Tuesday
$t 7=strtotime (Date ("Y-m-d", Strtotime ("6 Day")). " 23:59:59 ");//Mon
if ($t 2<1387420136&&1387420136<= $t 1) {
$c 1 + = 1;
}elseif ($t 3<1387420136&&1387420136<= $t 2) {
$c 2 + = 1;
}elseif ($t 4<1387420136&&1387420136<= $t 3) {
$c 3 + = 1;
}elseif ($t 5<1387420136&&1387420136<= $t 4) {
$c 4 + = 1;
}elseif ($t 6<1387420136&&1387420136<= $t 5) {
$c 5 + = 1;
}elseif ($t 7<1387420136&&1387420136<= $t 6) {
$c 6 + = 1;
}elseif (1387420136<= $t 7) {
$c 7 + = 1;
}
echo $c 1;
Break
Default:;
}
?>

Share to: more
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.