What is the purpose of a code block that isn't

2019-08-09 07:02发布

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条回答
Viruses.
2楼-- · 2019-08-09 07:28

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.

查看更多
登录 后发表回答