For the following php program with a switch statement, why '' give me $vSS=2 instead of =1? Quite strange to me. I am using PHP 5.5.9. I can add case '': to resolve the problem, but I am curious why PHP give $vSS=2 instead of $vSS=1. Is it normal or a bug?
<?php
R(15); // 1 ok
R(''); // why give me 2
R(40); // 2 ok
R(70); // 3 ok
#
function R($SS){
switch($SS){
case $SS<=20: $vSS=1;break;
case ($SS>20 and $SS<=49.9): $vSS=2; // why here?
if($SS == '') echo "DEBUG: SS is a null string.<br>\n";
break;
case ($SS<=100 and $SS>49.9): $vSS=3; break;
default:$vSS=0 ;
}
echo "DEBUG:(SS/vSS) $SS:$vSS\n";
}
?>
------ RESULT
DEBUG:(SS/vSS) 15:1
DEBUG: SS is a null string.<br>
DEBUG:(SS/vSS) :2
DEBUG:(SS/vSS) 40:2
DEBUG:(SS/vSS) 70:3
function R()?echo "DEBUG:(SS/vSS) $SS:$vSS\n";oh, I like it. @Barmar is right,switch - casedoesn't work like this