# PHP Variable

A variable is a temporary memory location that holds its data temporarily. PHP is said to be a loosely typed language, as it automatically corrects the data type of the variable, according on its value.

Syntax:

$variable_name=value; Rules for using PHP Variables: • PHP Variables starts with a$ sign followed by the variable name.
• PHP Variable name starts with a letter or underscore only; numbers and special characters are restricted for this.
• PHP Variables name can contain alphanumeric characters and underscores only.
• PHP Variable names are case sensitive.
• Putting a quote around the text value of the variables is necessary for the PHP Variables.
• PHP Variables are created and declared once the value is assigned to them.

## PHP Variables Scope:

PHP Variable Scope is used to specify the portion of the script where the variable can be used. These are:

• Local: Local Variables can only be accessed within the function where it is declared.
• Global: Global Variables can only be declared and accessed outside a function.
• Static: The variables inside a function gets deleted, once the function execution ends. The Static Variables contains the last information even after the completion of the function.

Example 1: Declaring PHP Variable with a Local scope

   Value of v is: $v "; } example(); echo " Value of v is:$v

"; ?>

Example 2: Declaring PHP Variable with a Global scope

   Value of v is: $v "; } example(); echo " Value of v is:$v

"; ?>

Example 3: Declaring Static PHP Variables

   "; example(); echo "
"; example(); ?>