dimanche 28 juin 2020

Why am I having syntax unexpected 'else' (T_ELSE) error? [closed]

I am following the instructions on PHP Documentation and I am trying the codes out in different ways. Somehow I got stucked somewhere I couldn't understand why I am getting T_ELSE error. According to No 12th Comment here: https://www.php.net/manual/en/control-structures.if.php one can call PHP variable from outside If function because IF doesn't have a scope, Below is what I did: Anyone please? Why is it not working this way?

<?php
// Your code here!

$foo = 89;

if ($foo <= 90)
{
    $h = "this is not right";
}
echo $h;

else {
    echo "this is true";
}
?>

Well the above doesn't work because the block else must follow if in this scenario and not other wise. The below code works however.

Aucun commentaire:

Enregistrer un commentaire