嘿伙计们,你对此有什么看法.
我希望在我的网站上设置一个标题图像(一个用于冬季,一个用于夏季),基于它是冬季或夏季.
所以我想知道最简单的方法是什么?我想使用日期('n')并查询返回值是否为冬季或夏季月份.
你会怎么做?
谢谢你的提示.
用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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
看似合法,它可能会有点浓缩,但我会把它作为练习留给读者.