[英]How to associate time (seconds) with a name
I am trying to get the time (seconds) from the server and then associate this to a student name: 我试图从服务器获取时间(秒),然后将其与学生姓名相关联:
$info = getdate();
$sec = $info['seconds'];
$current_sec = $sec;
echo $current_sec;
echo " | ";
if ($current_sec == '1') {echo 'John';}
else if ($current_sec == '2') {echo 'Mary';}
else if ($current_sec == '3') {echo 'Bill';}
~~~
else if ($current_sec == '60') {echo 'Bob';}
echo " | ";
echo $current_sec;
However I seem to get the same result each time no matter when I refresh the page: 但是,无论何时刷新页面,我似乎每次都得到相同的结果:
15 | 15 | John |
约翰| 1
1
where 15 is the actual seconds. 其中15是实际秒数。
I would be grateful for any help. 我将不胜感激任何帮助。
You're if statements have a typo: 如果陈述有拼写错误:
if ($current_sec = '1')
Is always true. 永远是真的。 Try:
尝试:
if ($current_sec == '1')
因为比较运算符是==
,而不是=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.