我对php变量范围感到困惑.如:
while(true){
$var = "yes , it is a test!";
}
printf($var)
Run Code Online (Sandbox Code Playgroud)
将$var在while语句范围的定义,我们怎么能拿它外面的范围是什么?我无法找到该文件的解释.
我想知道php如何处理它的范围.
如果你这样做了,while(true)你将无法摆脱这段时间,所以没关系。但如果你有一个真实的表达,像这样(我知道这是一个无用的例子)
$i=0
while($i<10){
$var = "yes , it is a test!";
$i++;
}
printf($var);
Run Code Online (Sandbox Code Playgroud)
只会工作。没有特殊的“while”变量范围,printf 将打印您的字符串。检查: http: //php.net/manual/en/language.variables.scope.php
| 归档时间: |
|
| 查看次数: |
3540 次 |
| 最近记录: |