Sunday, August 6, 2017

Describe about global and local scope.

Global and Local Scope

A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function:

Example

<?php
$x = 5; // global scope
function myTest() {
    // using x inside this function will generate an error    echo "<p>Variable x inside function is: $x</p>";
}
myTest();

echo "<p>Variable x outside function is: $x</p>";
?>