是否可以将代码片段包含在括号内的PHP中(不使用片段作为函数)?
以下代码的行为是否与没有大括号的行为相同?或者可能会出现问题,具体取决于括号内部或外部使用的代码类型?
例如,这将是:
<?php
// First Code-Block
{# several lines of code
}
// Second Code-Block
{# another several lines of code
}
?>
Run Code Online (Sandbox Code Playgroud)
始终表现得与此相同:
<?php
// First Code-Block
# several lines of code
// Second Code-Block
# another several lines of code
?>
Run Code Online (Sandbox Code Playgroud) echo "Point1, a=".$a."\n";
echo "Point1, b=".$b."\n";
if(1<2)
{
$a = 6;
$b['link'] = "here";
echo "Point2, a=".$a."\n";
echo "Point2, b[link]=".$b['link']."\n";
}
echo "Point3, a=".$a."\n";
echo "Point3, b[link]=".$b['link']."\n";
Run Code Online (Sandbox Code Playgroud)
为什么以上代码打印出以下内容?
Point1, a=
Point1, b=
Point2, a=6
Point2, b[link]=here
Point3, a=6
Point3, b[link]=here
Run Code Online (Sandbox Code Playgroud)
根据我的理解,$ a和$ b的范围应该在花括号{}内结束!