HTML
CSS
PHP
Deno
Examples
Do It Yourself
Blog
Type in your code below
Run
<?php //A global variable is a variable that can only be accessed outside of a function. //A local variable is a variable that can only be accessed within a function. //A static variable is a variable that still holds its value each time the function is called. $global_variable = "Hello World"; function globalScopeExample() { echo $global_variable; //will produce an error } function localScopeExample() { $local_variable = "Hello World"; echo $local_variable; //outputs: Hello World } function staticScopeExample() { static $static_variable = 10; echo $static_variable; $static_variable++; //Retains its value even after execution } globalScopeExample(); localScopeExample(); staticScopeExample(); //outputs: 10 staticScopeExample(); //outputs: 11 ?>
Related Chapters
PHP Math
PHP Operators
PHP Boolean
PHP Arrays
PHP Numbers
Related Examples
PHP Constants Example
PHP Math sqrt() Example
PHP Boolean Logical NOT Example
PHP Boolean Conversion Example
PHP Boolean Example