Thursday, February 2, 2012

Statement evaluation in php switch case

$input = 0;
if(@isset($input)) {
switch($input) {
case ($input>=0 && $input <=4):
echo 'Case 1';
break;
case $input == 5:
echo 'Case 2';
break;
}
}

//Output
Expecting o/p: Case 1
But orig o/p: Case 2

So, its advisable to use boolean/strings in the case. If you want to do evaluation go with 'if' and 'elseif' statement
 

Followers