-2
我下面的代码片段,请通过它去:与赋值运算符一起使用的逻辑非(!)运算符是否总是将赋值运算符左侧的变量赋值为false?
<?php
// Top of the page, before sending out ANY output to the page.
$user_is_first_timer = !isset($_COOKIE["FirstTimer"]);
// Set the cookie so that the message doesn't show again
setcookie("FirstTimer", 1, strtotime('+1 year'));
?>
<H1>hi!</h1><br>
<!-- Put this anywhere on your page. -->
<?php if($user_is_first_timer): ?>
Hello there! you're a first time user!.
<?php endif; ?>
在我的编码经验,大部分时间我见过像!isset($_COOKIE["FirstTimer"])
与if
声明语句。这是我一生中第一次和转让经营者一起观察这样的陈述。
在上面的代码中,我只想了解0语句做什么?
在此代码行中逻辑非(!)运算符的作用是什么?
请用清楚可靠的解释清楚我的疑惑。
谢谢。
单身!只是翻转一个布尔值。如果'isset($ _COOKIE [“FirstTimer”])'返回true,那么用户不是我假设的这个逻辑中的第一个定时器。那么分配给$ user_is_first_timer的是! + true(= false)... – marekful
请注意,'setcookie'的第二个参数应该是一个字符串。 – Progrock