note 35874 added to control-structures.switch
| From: | Maktub at rn2 dot php dot net | Date: | Wed, 17 Sep 2003 19:44:55 +0000 |
| Subject: | note 35874 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56654@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35874
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35874&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35874&report=yes