php if elseif else endif

Syntax with "endif" used mostly in complex templates where easier to find "endif" than "}":

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
if( $a > $b ):
 
    echo $a.' is greater than '.$b;
 
elseif( $a < $b ):
 
    echo $a.' is less than '.$b;
 
else:
 
    echo $a.' equals '.$b;
 
endif;
 
?>

Classic syntax:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
if( $a > $b ) {
 
    echo $a.' is greater than '.$b;
 
} elseif( $a < $b ) {
 
    echo $a.' is less than '.$b;
 
} else {
 
    echo $a.' equals '.$b;
 
}
 
?>

1 thought on “php if elseif else endif”

Leave a Comment