聘我网

新概念招聘3.0

PHP中的控制结构

vote up0vote downstar

PHP比较常见的循环是这样:

for($i = 0; $i < 5; $i++)
{
    echo $i . "\r\n";
}

但今天却才发现其实PHP中也支持类似VB风格的语法

for($i = 0 ; $i < 5; $i++): 
    echo $i . "\r\n";   
endfor;

if(true):
    echo 'good';
endif;

PHP offers an alternative syntax for some of its control structures; namely, if, while, for, foreach, and switch. In each case, the basic form of the alternate syntax is to change the opening brace to a colon (:) and the closing brace to endif;, endwhile;, endfor;, endforeach;, or endswitch;, respectively.

这种语法由于和html的相似性,所以在模板引擎中比较多见

 

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.