Svi*_*ish 1 php timestamp function
好吧,我担心这只是我忘记了一些关于PHP的小蠢事,但我似乎无法弄清楚这里发生了什么.
<?php header('Content-Type: text/plain');
$closingDate = mktime(23, 59, 59, 3, 27, 2009);
function f1()
{
return time() > $closingDate;
}
function f2()
{
return time() < $closingDate;
}
printf(' Time: %u
Closing: %u
t > c: %u
f1 : %u
t < c: %u
f2 : %u',
time(),
$closingDate,
time() > $closingDate,
f1(),
time() < $closingDate,
f2());
Run Code Online (Sandbox Code Playgroud)
问题是输出对我来说根本没有意义.我不明白为什么它会像它一样:
Time: 1235770914
Closing: 1238194799
t > c: 0
f1 : 1
t < c: 1
f2 : 0
Run Code Online (Sandbox Code Playgroud)
为什么函数输出的结果与函数内的代码不一样?我没有到这里来的是什么?我是否完全看不起自己的代码?到底是怎么回事?
你没有传递$closingDate给这些功能.他们是比较time反对null.
尝试:
function f1()
{
global $closingDate;
return time() > $closingDate;
}
function f2()
{
global $closingDate;
return time() < $closingDate;
}
Run Code Online (Sandbox Code Playgroud)
要么:
// call with f1($closingDate);
function f1($closingDate)
{
return time() > $closingDate;
}
// call with f2($closingDate);
function f2($closingDate)
{
return time() < $closingDate;
}
Run Code Online (Sandbox Code Playgroud)
查看有关变量作用域的PHP文档.