Tutorialsplane

PHP Static Keyword


PHP static Keyword:– We know how a local variable works inside a function .No one allowed to access local keyword outside the function that simply means that a local variable dies after the execution of function completeness.
If one requires this local variable to access again and again so the only way is to put keyword static before variable name.


PHP static Keyword| Example

Let us take an exampmle to understand static keyword in php.

Example

<?php function game(){
    static $x=10;
	echo $x;
	$x++;
	
	
}
game();
echo "<br?>";
game();
echo"<br/>";
game();

?>

PHP Tutorial