我无法在php程序中找出这个等式。有人可以帮帮我吗?
<?php
$year = 2013;
switch (($year - 4) % 12) {
case 0: $zodiac = 'Rat'; break;
case 1: $zodiac = 'Ox'; break;
case 2: $zodiac = 'Tiger'; break;
case 3: $zodiac = 'Rabbit'; break;
case 4: $zodiac = 'Dragon'; break;
case 5: $zodiac = 'Sanke'; break;
case 6: $zodiac = 'Horse'; break;
case 7: $zodiac = 'Goat'; break;
case 8: $zodiac = 'Monkey'; break;
case 9: $zodiac = 'Rooster'; break;
case 10: $zodiac = 'Dog'; break;
case 11: $zodiac = 'Pig'; break;
}
echo "{$year} is the year of the {$zodiac}.";
?>
答案 0 :(得分:0)
转换中的“$ year - 4”部分是为了使黄道带时间表符合公历。例如,今年(2013年)是蛇年。
2013 - 4 = 2009
2009 % 12 = 5
5在switch语句中评估为“Snake”。