Re: [請益] 請問變數的問題
※ 引述《jtorngl (煩死了啦!)》之銘言:
: 剛開始學PHP,在變數的部份有個問題想請教先進
: 在函數中只能使用區域變數,無法使用全域變數
: 如果要在函數中使用全域變數可使用
: global 宣告、GLOBALS 陣列
: 想請問宣告為global和宣告為static有何差別?
: Java的成員變數在類別內的方法也可使用
: 現在PHP多了一個global宣告突然腦袋打結了
<?php
/* static */
function oh() {
$a = 0;
static $b = 0;
echo 'a=' . $a++ . ' b=' . $b++ . '<br />';
}
for( $i=0; $i<5; $i++) oh();
/* global */
$boo = 'PHP: Hypertext Preprocessor';
function boo() {
global $boo;
echo $boo;
}
boo();
?>
try it.
--
The Internet: where men are men, women are men, and children are FBI agents.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.130.223.207
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章