Scope of Variable

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.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.