Php doesn't supports global scope variables inside a function without using the global keyword?

<?php
   $a ="helllo welcome to php! ....:)"; 
   function msg(){ 
       /* global $a; */
       echo $a;
   } 
   msg();
?>

Global variable $a is not accessible inside the function msg() but when i use global $a
then it is accessible, i want to know that it is accessible or not
without using global keyword inside or outside the function for the
particular variable

Output

Code

>Solution :

Why did you commented global $a ?

<?php
   $a ="helllo welcome to php! ....:)"; 
   function msg(){ 
       global $a;
       echo $a;
   } 
   msg();
?>

Leave a Reply