我有2個PHP文件。PHP變量穿越require_once和函數
的index.php:
<?php
$counter = 0;
require_once('temp.php');
temp();
echo $counter;
?>
temp.php:
<?php
function temp() {
tempHelper();
}
function tempHelper() {
$counter++;
}
?>
我想打印1不是0 我試圖$計數器設置沒有成功全局變量。
我該怎麼辦?
:)這裏
更多信息的鏈接http://php.net/manual/en/language.variables.scope.php –
沒有方式中的初始化設置$櫃檯讓他成爲全球? – Nir
在PHP中,沒有辦法讓用戶定義[超級全局](http://php.net/manual/en/language.variables.superglobals.php)。如果您想要這樣做,請重新考慮您的應用程序設計。 –