Home  >  Article  >  Backend Development  >  php alternative syntax

php alternative syntax

WBOY
WBOYOriginal
2016-07-30 13:29:511258browse

Output variables

<code><span><span><?</span>=<span>$variable</span><span>?></span></span></code>

foreach loop

<code><span><span><?php</span><span>foreach</span> (<span>$todo</span><span>as</span><span>$item</span>): <span>?></span></span><span><<span>li</span>></span><span><span><?</span>=<span>$item</span><span>?></span></span><span></<span>li</span>></span><span><span><?php</span><span>endforeach</span>; <span>?></span></span><span></<span>ul</span>></span></code>

if judgment

<code><span><span><?php</span><span>if</span> (<span>$username</span> == <span>'sally'</span>): <span>?></span></span><span><<span>h3</span>></span>Hi Sally<span></<span>h3</span>></span><span><span><?php</span><span>elseif</span> (<span>$username</span> == <span>'joe'</span>): <span>?></span></span><span><<span>h3</span>></span>Hi Joe<span></<span>h3</span>></span><span><span><?php</span><span>else</span>: <span>?></span></span><span><<span>h3</span>></span>Hi unknown user<span></<span>h3</span>></span><span><span><?php</span><span>endif</span>; <span>?></span></span></code>

Similar structures: endif, endfor, endforeach and endwhile, be careful not to use semicolons after each structure (except the last one), use colons

Copyright Statement: Knowledge comes from the people and is used by the people! Reprinting is welcome. Please attach a link to this article at the beginning. The article will be updated from time to time!

The above introduces the PHP alternative syntax, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn