我有以下会话值
$_SESSION["time"] = 2015-01-09 23:57:38 (example value)
和变量$test
$test = time() - (60 * 1); (1 minute)
$test = date("Y-m-d H:i:s",$test);
我想做的是检查 1 分钟是否过去了。为此,我有以下代码:
if(isset($_SESSION["time"]) && (strtotime($_SESSION["time"]) > $test)){
echo "first";
}else{
echo "second";
}
独立于我使用的逻辑比较(<或>),一分钟后页面刷新仍然回显相同......知道为什么吗?我觉得这真的很奇怪...或>
比较应该是这样的
($_SESSION["time"] > $test)
PHP 现在将比较两个字符串值,而不是整数(来自strtotime
调用的返回值)和字符串(来自date
调用的返回值)
他真正想要的是...
strtotime($_SESSION["time"]) > strtotime($test))