PHP.nl

else

else

Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what is for.
extends an statement to execute a statement in case the expression in the statement evaluates to false. For example, the following code would display if is greater than , and otherwise:

The statement is only executed if the expression evaluated to false, and if there were any expressions - only if they evaluated to false as well (see ).

`elseelseifif$a``$b````php

$b) { echo "a is greater than b"; } else { echo "a is NOT greater than b"; } ?>

`else``if``elseif`elseif

> **Opmerking:** > ### Dangling else
> 
> 
>    In case of nested - statements,
>    an  is always associated with the nearest .
>    
>    Despite the indentation (which does not matter for PHP), the 
>    is associated with the , so the example does not produce
>    any output. While relying on this behavior is valid, it is recommended to avoid
>    it by using curly braces to resolve potential ambiguities.
>   `if``else``else``if````php
> <?php
> $a = false;
> $b = true;
> if ($a)
>     if ($b)
>         echo "b";
> else
>     echo "c";
> ?>
> ```
> 
> `else``if ($b)`