0

Why php global declared varible cant be used inside the function?

As the question mention it seems kinda wierd. In most programming language I learn so far, global variable can be used from anywhere. So why doesn't php support this?

6th Jan 2017, 6:14 PM
RanjOyHunTer
RanjOyHunTer - avatar
3 odpowiedzi
+ 1
For this the $GLOBALS[] is used. For usage please read in the PHP manual: http://php.net/manual/en/reserved.variables.globals.php
6th Jan 2017, 6:18 PM
Manuel Wiltz
Manuel Wiltz - avatar
+ 1
$GLOBALS['VariableName'] used to access global variables from anywhere . Example : $name = 'Zardi' ; function msg() { echo "Name : ".$GLOBALS['name']; } msg(); // Name : Zardi
13th Apr 2017, 3:50 AM
Mahmoud Zardi
Mahmoud Zardi - avatar
0
thanks manuel
6th Jan 2017, 6:27 PM
RanjOyHunTer
RanjOyHunTer - avatar