Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例子
function a(){ $num = 1; function b(){ echo $num; // how to get $num value? } }
在这种情况下global不起作用,因为$num不是全局变量。
global
$num
function a() { $num = 1; function b($num) { echo $num; }; b($num); } a();
您可以使用 S_SESSION 来获取变量吗?
function a(){ $_SESSION['num'] = 1; function b(){ echo $_SESSION['num']; } }
不确定嵌套函数是顺便说一句的方法。