Everyone, let me clarify:
It is equivalent B.
It’s not “both,” it’s not sometimes one thing, sometimes it’s another, it’s always B. To understand why you sometimes see results indicating that it might be A, you need to understand how type coercion works in PHP .
false "" switch case, , FALSE.
switch if/elseif, (== ===) , switch ( ), case ( ).
:
$x = 0;
switch ($x) {
case $x > -1:
echo "case 1";
case $x == -1:
echo "case 2";
}
if/elseif:
A:
$x = 0;
if ($x > -1) {
echo "case 1";
} else if ($x == -1) {
echo "case 2";
}
B:
$x = 0;
if ($x == ($x > -1)) {
echo "case 1";
} else if ($x == ($x == -1)) {
echo "case 2";
}