Home >Backend Development >PHP Tutorial >php alternative syntax
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.