This article mainly shares with you PHP's detailed explanation of the number of weeks within a period of time when changing zones. It mainly uses code examples to share with you. I hope it can help you.
function numweeka($starttime,$endtime){ $arr = array('0'=>0,'1'=>0,'2'=>0,'3'=>0,'4'=>0,'5'=>0,'6'=>0); if($starttime-$endtime >= 0){ return '开始时间大于或等于结束时间'; }else if(date('Y-m-d',$starttime) == date('Y-m-d',$endtime)){ $arr[date('w',$starttime)] = 1;; return $arr; }else{ $n = ($endtime - $starttime)/(24*60*60); if($n <= 7){ for($i = $starttime;$i<$endtime;$i = $i +(24*60*60)){ switch(date('w',$i)){ case 0: $arr[0]++; break; case 1: $arr[1]++; break; case 2: $arr[2]++; break; case 3: $arr[3]++; break; case 4: $arr[4]++; break; case 5: $arr[5]++; break; case 6: $arr[6]++; break; } } return $arr; }else{ $num = intval($n/7); foreach($arr as $k => $v){ $arr[$k] = $num; } $a = date('w',$starttime); $b = date('w',$endtime); if($a != 0){ for($i =$a;$i<=6;$i++){ $arr[$i]++; } } if($b != 6){ for($i = 0;$i<=$b;$i++){ $arr[$i]++; } } return $arr; } } } $starttime = '952041600'; $endtime = '1457827199'; $dataa = numweeka($starttime,$endtime);
Related recommendations:
MySQL memory swap area caused a
php weekly data writing related problem code
Find the initial date and end date of the week if the year and week number are known in php
The above is the detailed content of PHP's detailed explanation of the number of weeks within a period of time when changing zones. For more information, please follow other related articles on the PHP Chinese website!