Scope of Variable
Scope of Variable
PHP do not require to declare a variable before use. This can be handy when we just need to get something done but problematic when troubleshooting.Some languages have syntax to prevent these types of errors from occurring. In PHP, for example, to use a global variable inside a function, you must use the global keyword.
$sample = “Test”;
function Display()
{
global $sample; // variable can now be used in function
echo $sample; // will display “Test”
}
Global variables are accessible even within multiple include files.
