[Solved] Why is PHP handling the dangling else differently? [closed]


Your first code reads as

$a = false;
if ($a) {
    echo 'A';
}

if (false) {
    echo 'B';
}
else {
    echo 'C';
}

When you do not use braces, only the next statement (statement, not line) gets executed as part of that control structure. It is not ambiguous as this behaviour is clearly defined in the programming language.

1

solved Why is PHP handling the dangling else differently? [closed]