大家好,
你对此有何看法?
我想根据是冬季还是夏季在我的网站上设置一个标题图像(一个用于冬季,一个用于夏季)。
所以我想知道最简单的方法是什么?我想到使用 date('n') 并查询返回的值对于冬季或夏季月份是否为真。
你会怎么办?
谢谢你的提示。
谷歌搜索并发现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;
}
}
}
看起来合法,它可能可以压缩一点,但我会将其作为练习留给读者。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)