note 97832 deleted from control-structures.switch by crell
| From: | crell@php.net | Date: | Mon, 27 Jun 2022 20:36:38 +0000 |
| Subject: | note 97832 deleted from control-structures.switch by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218628@lists.php.net to get a copy of this message | ||
Note Submitter: mr at bwsolution dot de
----
"loose comparison" means that switch won't check the type.
switch will only compare values:
<?php
if('a string' == 0) echo 'a string is 0' . PHP_EOL;
if('a string' === 0) echo 'but you will never see this' . PHP_EOL;
switch(0){
case 'a string': echo 'a string' . PHP_EOL;
case 'another string': echo 'another string' . PHP_EOL;
}
if('a string' == true) echo 'a string is TRUE' . PHP_EOL;
if('a string' === true) echo 'but you will never see this' . PHP_EOL;
switch(true){
case 'a string': echo 'a string' . PHP_EOL;
case 'another string': echo 'another string' . PHP_EOL;
}
?>
will output:
a string is 0
a string
another string
a string is TRUE
a string
another string