PHP Variables

Definition of PHP Variables

A PHP variables name cannot start with a number. A variable name can only contain alphanumeric characters and underscores (A-z, 0-9, and _ )

First of all Variable names are case-sensitive ($male and $MALE are two different variables)

  • We know that very well, variables always stored the data.
  • A variable is a temporary storage that is used to store data temporarily.
  • In PHP, a variable is declared using $ sign followed by a variable name. i.e. $country.


PHP Variable: Declaring string, integer, and float
the example to store string, integer and float values in PHP variables.

File: example1.php


PHP Variable: Sum of two variables
File: example2.php


PHP Variable: case sensitive
therefore,  variable names are case sensitive. So variable name “color” is different from Color, COLOR, COLor etc.

File: example3.php


  • finally, The PHP variables start with the $ sign, (i.e. $Car) followed by the name of the variable and In PHP name always must start with a letter or the underscore character only but the name can not start with a number.