A static variable retains its value between calls to a
function but is visible only within that function.
IT declare a variable static with the static keyword.
IT declare a variable static with the static keyword.
function test_counter ( ) {
static $counter = 0;
$counter++;
echo "Static counter is now $counter\n";
}
$counter = 5;
test_counter( );
test_counter( );
echo "Global counter is $counter\n";
Static counter is now 1
Static counter is now 2
Global counter is 5
Variables declared outside a function are global.
That is, they can be accessed from any part of the script. By default,
they are not available inside functions.