<?php // 測定開始日 $start_day = strtotime('2016/04/23'); $today = strtotime( date('Y/m/d') ); $count_week = 8; //終了日を出すために週に+1 $count_end = $count_week + 1; $i = 0; $ret = array(); $ret2 = array(); while( $count_end >= $i ){ $ret[$i] = strtotime( $i.'week', $start_day); $ret2[$i] = date('Y/m/d' ,strtotime( $i.'week', $start_day)); if( $i >= 1){ $range_start = $ret[$i - 1]; $range_end = strtotime( '-1 day', $ret[$i]); if( in_array($today, range( $range_start, $range_end ) ) ) echo $i."週目に該当<br>" ; } $i++; } print_r($ret); print_r($ret2); ?>
<?php $start_day = strtotime('2016/04/21'); $add = 7*8; // カレンダー作成 $week_count=1; $ary=array(); for($i=0; $i<$add; $i++) { $buf = strtotime($i. ' days', $start_day); $ary[date('Y/m/d', $buf)]['date'] = date('Y/m/d', $buf); $ary[date('Y/m/d', $buf)]['w'] = date('w', $buf); if($i%7==0 and $i!=0) $week_count++; $ary[date('Y/m/d', $buf)]['week_count'] = $week_count; } print_r($ary); // 該当日抽出 $today = date('Y/m/d'); if(array_key_exists($today, $ary)){ print_r($ary[$today]); } ?>
なるほどー。