What does the ":" mean at the end of the PHP if statement?

What does :the end of the expression mean ?

<?
if(!validateName($_POST['name'])):
?>
+3
source share
4 answers

Colon operator (:), mainly used in php and html inline coding.

Using this operator, you can avoid using curly braces. This operator reduces the complexity of inline coding. You can use this operator (:) with if, while, for, foreach, etc.

Without operator (:)

<body>
<?php if(true){ ?>
<span>This is just test</span>
<?php } ?>
</body>

With operator (:)

<body>
<?php if(true): ?>
<span>This is just test</span>
<?php endif; ?>
</body>
+4
source

PHP ; , , while, for, foreach switch. (:) endif;, endwhile;, endfor;, endforeach;, endswitch; .

<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>

ref:

+3

The ':' operator after the operator if()is a multi-line if statement. It will be interrupted after some code (most likely in a language other than PHP) on <? endif ?>.

0
source

This is the endif syntax (http://www.phpbuilder.com/manual/migration.if-endif.php) and is used as follows:

<?
if(!validateName($_POST['name'])):
    echo "Something";
endif;
?>

This style is useful in php scripts when interacting with Javascript and HTML.

0
source

All Articles