Re: [請益] 請問變數的問題

看板PHP作者 (任性)時間18年前 (2007/05/18 02:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #16J9Z0m_ (PHP)
討論串 (同標題文章)
文章代碼(AID): #16J9Z0m_ (PHP)