Can the following code be abbreviated? Is there a simple way to implement the following code? I think it is too complicated to write this code. if I write data for a month, wouldn't I need to write 30 cases for help, I am a newbie & lt ;? Phpdate_default_timezone_set (PRC); $ c10; $ c20; $ c30; $ c40; $ c50; $ 60; $ c70; $ w & nbsp; date (can these codes be abbreviated below?
Is there a simple way to implement the following code? I think it is too complicated to write this code. if I write data for a month, wouldn't I need to write 30 cases?
Please help me. I am a newbie.
Date_default_timezone_set ('prc ');
$ C1 = 0;
$ C2 = 0;
$ C3 = 0;
$ C4 = 0;
$ C5 = 0;
$ C6 = 0;
$ C7 = 0;
$ W = date ("w", time ());
Switch ($ w ){
Case 1:
Break;
Case 2:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Tuesday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif (1387420136 <=$ t2 ){
$ C2 + = 1;
}
Echo $ c1;
Break;
Case 3:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Wednesday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Tuesday
$ T3 = strtotime (date ("Y-m-d", strtotime ("-2 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif ($ t3 <1387420136 & 1387420136 <= $ t2 ){
$ C2 + = 1;
} Elseif (1387420136 <= $ t3 ){
$ C3 + = 1;
}
Echo $ c1;
Break;
Case 4:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Thursday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Wednesday
$ T3 = strtotime (date ("Y-m-d", strtotime ("-2 day"). "23:59:59"); // Tuesday
$ T4 = strtotime (date ("Y-m-d", strtotime ("-3 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif ($ t3 <1387420136 & 1387420136 <= $ t2 ){
$ C2 + = 1;
} Elseif ($ t4 <1387420136 & 1387420136 <= $ t3 ){
$ C3 + = 1;
} Elseif (1387420136 <=$ t4 ){
$ C4 + = 1;
}
Echo $ c1;
Break;
Case 5:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Friday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Thursday
$ T3 = strtotime (date ("Y-m-d", strtotime ("-2 day"). "23:59:59"); // Wednesday
$ T4 = strtotime (date ("Y-m-d", strtotime ("-3 day"). "23:59:59"); // Tuesday
$ T5 = strtotime (date ("Y-m-d", strtotime ("-4 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif ($ t3 <1387420136 & 1387420136 <= $ t2 ){
$ C2 + = 1;
} Elseif ($ t4 <1387420136 & 1387420136 <= $ t3 ){
$ C3 + = 1;
} Elseif ($ t5 <1387420136 & 1387420136 <= $ t4 ){
$ C4 + = 1;
} Elseif (1387420136 <=$ t5 ){
$ C5 + = 1;
}
Echo $ c1;
Break;
Case 6:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Saturday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Friday
$ T3 = strtotime (date ("Y-m-d", strtotime ("-2 day"). "23:59:59"); // Thursday
$ T4 = strtotime (date ("Y-m-d", strtotime ("-3 day"). "23:59:59"); // Wednesday
$ T5 = strtotime (date ("Y-m-d", strtotime ("-4 day"). "23:59:59"); // Tuesday
$ T6 = strtotime (date ("Y-m-d", strtotime ("-5 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif ($ t3 <1387420136 & 1387420136 <= $ t2 ){
$ C2 + = 1;
} Elseif ($ t4 <1387420136 & 1387420136 <= $ t3 ){
$ C3 + = 1;
} Elseif ($ t5 <1387420136 & 1387420136 <= $ t4 ){
$ C4 + = 1;
} Elseif ($ t6 <1387420136 & 1387420136 <= $ t5 ){
$ C5 + = 1;
} Elseif (1387420136 <= $ t6 ){
$ C6 + = 1;
}
Echo $ c1;
Break;
Case 7:
$ T1 = strtotime (date ("Y-m-d"). "23:59:59"); // Sunday
$ T2 = strtotime (date ("Y-m-d", strtotime ("-1 day"). "23:59:59"); // Saturday
$ T3 = strtotime (date ("Y-m-d", strtotime ("-2 day"). "23:59:59"); // Friday
$ T4 = strtotime (date ("Y-m-d", strtotime ("-3 day"). "23:59:59"); // Thursday
$ T5 = strtotime (date ("Y-m-d", strtotime ("-4 day"). "23:59:59"); // Wednesday
$ T6 = strtotime (date ("Y-m-d", strtotime ("-5 day"). "23:59:59"); // Tuesday
$ T7 = strtotime (date ("Y-m-d", strtotime ("-6 day"). "23:59:59"); // Monday
If ($ t2 <1387420136 & 1387420136 <= $ t1 ){
$ C1 + = 1;
} Elseif ($ t3 <1387420136 & 1387420136 <= $ t2 ){
$ C2 + = 1;
} Elseif ($ t4 <1387420136 & 1387420136 <= $ t3 ){
$ C3 + = 1;
} Elseif ($ t5 <1387420136 & 1387420136 <= $ t4 ){
$ C4 + = 1;
} Elseif ($ t6 <1387420136 & 1387420136 <= $ t5 ){
$ C5 + = 1;
} Elseif ($ t7 <1387420136 & 1387420136 <= $ t6 ){
$ C6 + = 1;
} Elseif (1387420136 <= $ t7 ){
$ C7 + = 1;
}
Echo $ c1;
Break;
Default :;
}
?>
Share: More