Home » Programming » php » PHP Variables

# PHP Variables

Variables are those which is used to store the information. They act like a container. It start with ‘$’ this sign and follow by name of the variable. Variable name should either start with Underscore or some letter but I can never start with a number. Example: Result: My name is PHP 1 1.9 Explanation:$txt always hole the value of some text word then $x and$y will hold the value of some numerical.

Now moving further, PHP has three different types of variable scopes in a program. The three are :

Global

The variable which is declared outside the function then is called Global variable. This variable can be access outside the particular function.

Example:

Result:
This function has Variable:
This function has Variable: 20

Explanation: The variable was declared outside the function will not be call up inside the function, it can only be called at outside the function. While calling the global variable inside the function will give some error.

Local

The variable which is declared inside the function then is called Local variable. This variable can be only access inside the function.

Example:

Result:

Inside Variable is: 20
Outside Variable is:

Explanation: The variable was declared inside the function will not be call up outside the function, it can only be called at inside the function. While calling the local variable outside the function will give some error.

Static

Example:

Result:
10
9
8
7
6

Explanation: In this static type variable, whenever this variable is been called it will for sure give you some output.

Managed by MochaHost - Fast & Easy WordPress Hosting