note 21808 deleted from control-structures.switch by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 19:42:53 +0000 |
| Subject: | note 21808 deleted from control-structures.switch by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218741@lists.php.net to get a copy of this message | ||
Note Submitter: chernyshevsky at hotmail dot com
----
Be very careful when you're using text strings as cases. If the variable supplied to switch()
is an integer, the cases would be converted to integer before the comparison is made (usually to
zero). The following snippet prints "hello".
<?php
$a = 0;
switch($a) {
case 'Hello': echo "Hello";
break;
}
?>