-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