Php Variables

It provides the memory location to store or hold any type of value which is defined with variables type.

Declaring PHP Variables

In PHP, a variable starts with the $ sign, followed by the name of the variable.

Example :-

Result

Hello world!
5
10.5

Output Variables

The PHP echo statement is often used to output data to the screen.

Example :-

Result

I love dwtutorials.com!

Local variable

A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function.

Example

Result

Variable x inside function is: 5
Variable x outside function is:

Global variables

A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function.

Example

Result

Variable x inside function is:
Variable x outside function is: 5

Statics Variables

Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.

Example

Result

0
1
2