+ 3
why global variables cant be accessed from within a function?
global variables can be accessed from anywhere in a programme.
6 odpowiedzi
0
use global keyword before using them like
<?php $x=10 //is a global variable then
function func (){
global $x;
//use global keyword then these var are accessible
}
?>
0
i know this bt y it is so in php. ....y we cant use it directly
0
This maybe about scope. The $x inside the function does not know if you are talking about a local variable $x or global variable $x. So first it tries to search $x locally but there is no $x locally, hence an error occurs
- 1
what i didn't get u?
- 1
why we have to use global keyword....cant we use global variables directly
- 1
I'm not now