PHP Variable Scope PHP has three types of variable scopes: 1.) Local variable 2.) Global variable 3.) Static variable Local variable :- The variables that are declared within a function are called local variables. => These local variables have their scope only in that particular function in which they are declared. => These variables cannot be accessed outside the function, as they have local scope. Global variable :- The global variables are the variables that are declared outside the function. => These variables can be accessed anywhere in the program. => To access the global variable within a function, use the GLOBAL keyword before the variable. => However, these variables can be directly accessed or used outside the function without any keyword. Static variable :- Static variables exist only in a local function, but it does not free its memory after the program execution leaves the scope. => It is a feature of PHP to delete the variable, once it completes its execution and memory is freed. => Sometimes we need to store a variable even after completion of function execution. => Therefore, another important feature of variable scoping is static variable. => We use the static keyword before the variable to define a variable, and this variable is called as static variable. - Study24x7
Social learning Network
16 followers study24x7 16 Mar 2021 11:01 AM study24x7 study24x7

PHP Variable Scope PHP has three types of variable scopes: 1.) Local variable 2.) Global variable 3.) Static variable Local variable :- The variables that are declared within a function are called local variables. => These local variables have their scope only in that particu...

See more

study24x7
Write a comment
Related Questions
500+   more Questions to answer
Most Related Articles