将变量从php作用域传递到同一页面的另一个php作用域


Pass variable from php scope to another php scope in same page

我想获得存储在另一个php作用域的变量值

<?php
    $count=3;
?>
<?php
    echo($count); //does not print the value
?>

在你的例子中,它必须显示3之前

检查:http://php.net/manual/en/language.variables.scope.php

这个链接有很多类似你在这里列出的例子。

http://php.net/manual/en/language.variables.scope.php

尝试使用var_dump($varname)

你不需要把圆括号(在var周围)

<?php
$count=3;
echo $count; //will work
var_dump($count) //when in doubt, look at what is in the variable
?>