$bytes = 0;
switch($bytes){
case $bytes == 0:
echo 'Equal to 0.';
break;
case $bytes < 0:
echo 'Less than 0.';
break;
}
This outputs “Less than 0.”
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
switchstatements don’t work like that. When checking eachcase, the value is compared to thecasevalue (using==).So, PHP is doing:
$bytes == ($bytes == 0)? Which is:$bytes == (true). This isfalse, so it’s skipped.$bytes == ($bytes < 0)? Which is:$bytes == (false). This istrue, so it runs that block.You need to use an
if/elsehere.