Why does the code snippet provided only execute the else statement instead of the nested IF statement?

The issue with the code snippet is that the nested IF statement is missing curly braces {}. Without the curly braces, only the immediately following statement is considered part of the IF block. To solve this issue, the nested IF statement should be enclosed within curly braces to ensure that both the IF and ELSE blocks are executed correctly.

<?php
$var1 = 10;
$var2 = 20;

if ($var1 > $var2) {
    echo "Var1 is greater than Var2";
} else {
    if ($var1 < $var2) {
        echo "Var1 is less than Var2";
    } else {
        echo "Var1 is equal to Var2";
    }
}
?>