<?php
$year = 2001; //这里输入的年份
$month = 10; //这里输入的月份
switch ($month) {
case 1:
echo "{$year}年{$month}月的天数是31天";
break;
case '3':
echo "{$year}年{$month}月的天数是31天";
break;
case '5':
echo "{$year}年{$month}月的天数是31天";
break;
case '7':
echo "{$year}年,{$month}月的天数是31天";
break;
case '8':
echo "{$year}年,{$month}月的天数是31天";
break;
case '10':
echo "{$year}年,{$month}月的天数是31天";
break;
case '12':
echo "{$year}年,{$month}月的天数是31天";
break;
case '4':
echo "{$year}年,{$month}月的天数是30天";
break;
case '6':
echo "{$year}年,{$month}月的天数是30天";
break;
case '9':
echo "{$year}年,{$month}月的天数是30天";
break;
case '11':
echo "{$year}年,{$month}月的天数是30天";
break;
case '2':
if($year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0 ){
echo "{$year}年,{$month}月的天数是29天";
}else{
echo "{$year}年,{$month}月的天数是28天";
}
break;
default:
echo '你TM乱输入什么玩意,艹!';
break;
}
?>
这里再交给大家一个简单的写法,就是天数一样的月份 让他break取消;直接穿越过去!
<?php
$year = 2001; //这里输入的年份
$month = 10; //这里输入的月份
switch ($month) {
case '1':
case '3':
case '5':
case '7':
case '8':
case '10':
case '12':
echo "{$year}年,{$month}月的天数是31天";
break;
case '4':
case '6':
case '9':
case '11':
echo "{$year}年,{$month}月的天数是30天";
break;
case '2':
if($year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0 ){
echo "{$year}年,{$month}月的天数是29天";
}else{
echo "{$year}年,{$month}月的天数是28天";
}
break;
default:
echo '你TM乱输入什么玩意,艹!';
break;
}
?>
第二种看着是不是简单很多呢?! 嗯哼?