我遇到問題。我正在嘗試使用PHP比較當年與某一年的情況,但根據我的編碼,它總是返回true。我在下面解釋我的代碼。在使用PHP比較兩年時始終保持真實
$datestr="2020-2029";
$curryear=date("Y");
$yearArr=explode("-",$datestr);
$strYear=strtotime($yearArr[0]);
if($curryear < $strYear){
$flag=true;
}else{
$flag=false;
}
echo $flag;
在這裏,我需要-
之前的第一年應該是本年度的before year/same year
。請幫我解決這個問題。
$ strYear = strtotime($ yearArr [0]); 將返回2016年的時間戳,它返回1496261760,並且始終大於2017年。 使用 '$ strYear = $ yearArr [0];' –
爲什麼你想要做時間? – sumit