输出变量
<code><span><span></span>=<span>$variable</span><span>?></span></span></code>
foreach 循环
<code><span><span><?php </span><span>foreach</span> (<span>$todo</span><span>as</span><span>$item</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></span></code>
if 判断
<code><span><span><?php </span><span>if</span> (<span>$username</span> == <span>'sally'</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>h3</span>></span>Hi Joe<span><span>h3</span>></span><span><span><?php </span><span>else</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></span></code>
类似结构:endif,endfor,endforeach 和 endwhile ,每个结构以后注意不要使用分号(除了最后一个),用冒号
版权声明:知识取之于民,用之于民!欢迎转载,转载请开头附上本文链接,不定期更新文章!
以上就介绍了php替代语法,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。