php生成按指定时间以来年、季度、月份的下拉列表
直接循环,如果是月,则循环变量每次增加1(月),如果是年,则每次增加12(月),同时输出date('Y-m')或者 date('Y'),实例代码如下:
- function countSeason($start,$end){
- $temp = date("Y-m",strtotime("$start +3month"));
- while ($temp <= $end){
- $time[] = $temp;
- $temp = date("Y-m",strtotime("$temp +3month"));
- }
- return $time;
- }
- $time = countSeason("2008-10",date("Y-m"));
- ?>
- <select name="select_season" >
- <option> 按季度查看 </option>
- <?php foreach ($time as $val){?>
- //开源代码phpfensi.com
- <option value="http://www./<?php echo $val;?>"><?php echo substr($val,0,4);?>年 第<?php
- $temp = intval(substr($val,5,2));
- if (0<$temp&&$temp<4)
- {echo "1";}
- elseif (3<$temp&&$temp<7)
- {echo "2";}
- elseif (6<$temp&&$temp<10)
- {echo "3";}
- else
- {echo "4";}
- ?>季度</option>
- <?php }?>
- </select>