PHP switch function doesn't recognize "less than 0"

php

Solution

`switch` statements don't work like that. When checking each `case`, the value is compared to the `case` value (using `==`).

So, PHP is doing:

- Does `$bytes == ($bytes == 0)`? Which is: `$bytes == (true)`. This is `false`, so it's skipped.

- Does `$bytes == ($bytes < 0)`? Which is: `$bytes == (false)`. This is `true`, so it runs that block.

You need to use an `if/else` here.

$bytes = 0;
if($bytes == 0){
    echo 'Equal to 0.';
}
elseif($bytes < 0){
    echo 'Less than 0.';
}

Problem

``` $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?

Original source