What is the purpose of a code block that isn't part of an if/function etc

好久不见. 提交于 2019-12-13 19:30:12

问题


E.g.

<?php

echo "hello word";

$test = 1;

{

//sample php code inside code block

}

?>

Why is sample php code inside that code block. Is it purely to keep any variables defined inside it within the scope of the code block so no variables outside the code block get over written?


回答1:


It is most probably just for readability, since it doesn't create a new variable scope or something like this. Also as from the manual:

[...]Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter.



来源:https://stackoverflow.com/questions/31512254/what-is-the-purpose-of-a-code-block-that-isnt-part-of-an-if-function-etc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!