我希望在我的网站上设置一个标题图片(一个用于冬季,一个用于夏季),因为它是冬季或夏季。
所以我想知道最简单的方法是什么?我想使用日期('n')并查询返回值是否为冬季或夏季月份。
你会做什么?感谢您的提示。
答案 0 :(得分:6)
用Google搜索并找到http://www.geekpedia.com/code152_Get-The-Current-Season.html
function GetSeason() {
$SeasonDates = array('/12/21'=>'Winter',
'/09/21'=>'Autumn',
'/06/21'=>'Summer',
'/03/21'=>'Spring',
'/01/01'=>'Winter'); //this needed to be at Jan 1st
foreach ($SeasonDates AS $key => $value) // Loop through the season dates
{
$SeasonDate = date("Y").$key;
if (strtotime("now") > strtotime($SeasonDate)) // If we're after the date of the starting season
{
return $value;
}
}
}
似乎是合法的,它可能会有点浓缩,但我会将其作为练习留给读者。
答案 1 :(得分:2)
是的,你应该使用date('n')
。例如:
function get_image()
{
$summer = array(4,5,6,7,8,9);
return in_array(date('n'), $summer) ? 'summer.png' : 'winter.png';
}