note 35874 deleted from control-structures.switch by didou

From: Date: Sun, 09 Nov 2003 15:15:28 +0000
Subject: note 35874 deleted from control-structures.switch by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-60168@lists.php.net to get a copy of this message
Note Submitter: Maktub ---- I think Switch has a "rare" behavior with variables types matter: <?php // --- CODE $var1 = '+3'; $var2 = ' 3'; switch($var1): case $var2: echo "TRUE??? '$var1' and '$var2' is not equal! is false!\n"; break; endswitch; // --- END CODE ?> Return: TRUE??? '+3' and ' 3' is not equal! is false! Because it transforms in Integer the String type vars to compare in Switch? The vars are string type, not Integers. A possible solution: add a letter with the number, example: "!3" or "s3"...: <?php // --- CODE $var1 = '!+3'; $var2 = '! 3'; switch($var1): case $var2: echo "TRUE??? '$var1' and '$var2' is not equal! is false!\n"; break; endswitch; // --- END CODE ?> Return: (nothing) -- Maktub.

« previous php.notes (#60168) next »