php if elseif else endif

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

<?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:

<?php
if( $a > $b ) {
	echo $a.' is greater than '.$b;
} elseif( $a < $b ) {
	echo $a.' is less than '.$b;
} else {
	echo $a.' equals '.$b;
}
?>

One thought on “php if elseif else endif

Leave a Reply

Your email address will not be published. Required fields are marked *