|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-26 22:56 UTC] felipe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 05:00:01 2025 UTC |
Description: ------------ When I run this: for ($a=1;$a<10;$a++){ drawstar($a); } function drawstar($a){ $txt="*"; for ($ct=0;$ct<$a;$ct++){ echo $txt; } echo "\n"; } I get a printout of the stars. The $txt variable is local to the function. If I make $txt global scope to the entire file like below it won't work. $txt="*"; for ($a=1;$a<10;$a++){ drawstar($a); } function drawstar($a){ for ($ct=0;$ct<$a;$ct++){ echo $txt; } echo "\n"; } Expected result: ---------------- Variable defined globally should be accessible anywhere. Actual result: -------------- Nothing happens