Categories
PHP Tutorials

Static Variables in PHP with simple example

Static Variables in PHP with simple example. It retains the local variable value and it donot loose its value at the end of function call.

Static in PHP:

Retains the local variable value and it donot loose its value at the end of function call.

<?php
function f()
{
static $x=1;
echo $x.”<br />”;
$x++;
}
f();
f();
?>

Output  of this program:

1
2