Alternative Control Structure:
PHP provides alternative ways to use control structures like if, else, elseif, for, while, foreach etc. In each control structure we can replace the opening brace with a colon(:) and the closing brace with endif; endfor, endwhile, endforeach, respectively.
We can put any HTML coding within any control structure, the examples are given below:
elseif and else if will be considered identical only if these are used with curly braces otherwise if we want keep else and if must not be separated into two words, PHP will fail to recognize and would produce an error.
Example:
<?php
$a
=133;$b
=44;if
($a>$b):echo
"\$a is greater";else
: echo "\$b is greater";endif
;?>
Output:
$a is greater
Example:
<?php
$a
=133;$b
=44;if
($a>$b):?>
<
b>A is greater</b><?
else
:?>
<
i>B is greater</i><?php
endif
;?>
Output:
A is greater
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.