PHP 语法:指令分隔符(分号)
问题
我们在编写 PHP 代码的时候,怎样才算完成一条完整代码的编写呢?
回答
在编写 PHP 代码的时候,我们需要在每一行代码指令后面添加一个分号 ; 才算完成一行代码的编写。由于 ?> 中隐含了一个分号 ;,所以代码中在 ?> 前面的最后一行代码可以不添加分号 ;。
示例
错误示例
<?php
echo "This is a test" // 这里遗漏了分号
<?php
echo "This is a test" // 这里遗漏了分号
echo "This is a test";
?>
正确示例
<?php
echo "This is a test";
?>
<?php
echo "This is a test";
?>
<?php
echo 'We omitted the last closing tag';
PHP 社区 Wiki
关于 LearnKu
推荐文章: