note 97112 deleted from control-structures.switch by cmb

From: Date: Sun, 21 Apr 2019 11:54:04 +0000
Subject: note 97112 deleted from control-structures.switch by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210649@lists.php.net to get a copy of this message
Note Submitter: hackajar yahoo com ---- Apparently you need to be extra careful with "0" (zero) in your case statements when mixing int and string values: switch($key) { case 0: echo "only if I am zero";break; case 1: echo "I'm one";break; case "E1": echo "Why don't you output me?";break; default: echo "No value Found"; } Switch will be convinced that you mean "0" when you really mean "E1" unless you wrap it in quotes: switch($key) { case '0': echo "only if I am zero";break; case 1: echo "I'm one";break; case "E1":echo "Yay! I'm back!";break; default: echo "No value Found"; } Maybe this is what they mean by "loose comparison" with True, False operators?

« previous php.notes (#210649) next »