问题
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