Introduction
In my previous blog, I talked about a basic introduction to PHP.
In this blog, we will discuss "PHP VARIABLES".
PHP Variables
What is Variable?
- Variables are used to store the value and access the stored value in the program.
In PHP, variables begin with the "$" symbol, followed by the Variable name.
Example:
- <?php
- $a = 2;
- ?>
Rules for assigning a Variables:
Basically, a Variable can have a short name (like i,e., x,y,etc..) or larger names (like i,e., first,age_group,etc..),
- A Variable name must start with underscore characters or with a letter.
- A Variable name cannot begin with numbers.
- A variable name can contain only alpha-numeric characters and underscores ( A-Z, 0-9 and _ ).
- Variable names are case-senstive($NAME, $name), these names are two different variable names.
PHP OUTPUT VARIABLES
- The "echo" statement is often used to show the output to the screen.
Example 1
- <?php
- $m = "BEST WISHES!";
- echo"$m";
- ?>
Example 2
- <?php
- $a = 2;
- $b = 1;
- echo $a + $b ;
- ?>
PHP VARIABLES SCOPE
- Variables are declared anywhere in the program script.
- A PHP consist of three types of variable scopes:
- Global
- Local
- Static
Global Variable
- A variable declared outside of the function is known as a global variable.
- It can be accessed outside of the function and anywhere in the program.
Example 1

Join the conversation! Your thoughts help the community grow.