Sunday , December 16 2018
Home / Web Technologies / PHP / Lesson 4 : PHP VARIABLES -2

Lesson 4 : PHP VARIABLES -2

PHP Variables are depends upon the scope was divided into 4 types. Scope is nothing but defined as the range of availability a variable has to the program in which it is declared. The Four types of PHP Variables are :

Local variables
Function parameters
Global variables
Static variables

PHP Local Variables:

A variable declared in a function is considered local; that is, it can be referenced solely in that function. Any assignment outside of that function will be considered to be an entirely different variable from the one contained in the function:

This will produce the following result.

PHP Function Parameters:

In short, a function is a small unit of program which can take some input in the form of parameters and does some processing and may return a value.Function parameters are declared after the function name and inside parentheses. They are declared much like a typical variable would be:

This will produce the following result:

PHP Global Variables:

In contrast to local variables, a global variable can be accessed in any part of the program.However, in order to be modified, a global variable must be explicitly declared to be global in the function in which it is to be modified. This is accomplished, conveniently enough, by placing the keyword GLOBAL in front of the variable that should be recognized as global.Placing this keyword in front of an already existing variable tells PHP to use the variable having that name. Consider an example:

This will produce the following result:

PHP Static Variables:

The final type of variable scoping that I discuss is known as static. In contrast to the variables declared as function parameters, which are destroyed on the function’s exit, a static variable will not lose its value when the function exits and will still hold that value should the function be called again.
You can declare a variable to be static simply by placing the keyword STATIC in front of the variable name.

This will produce the following result:

Print Friendly, PDF & Email

Give us your valuable feedback

comments

About Kadiyala

Check Also

Lesson 1 : Introduction to PHP

Introduction to PHP : PHP is introduced by RASMUS LERDORF in 1994. It is an …