Domesticated Brain

PHP Variables

Before we go through the PHP variables it’s better to get a general idea about the variable in programming

What is a variable?

A variable is a way of storing information in your computer. This information can vary. We can also define variable as a container or a storage space that holds information in the memory which can be reused through out the program

In mathematics variables are named as letters like x and y. but in programming, programmers named them with more meaningful, descriptive names. We can assign a variable to an element of a program like user inputs, a number, name of a database, or a calculated value.

Declaring PHP variables

In PHP programming the name of the variable should be started with $ sign.


$domain = "";
          echo "$domain";

The output of the above PHP program is

Because the variable $domain assigned to value


Following are the few rules to be considered when declaring a variable in PHP programming language.


In PHP programming language we do not need to declare the data type because PHP automatically convert the variable into a required data type.

To assign a value we use (=) assign operator.

$domain = "";

Variable should be started with the $ sign Ex- $domain

The name of the variable can start with letter or (_)underscore sign and it’s case sensitive. That is variable $domain and $DOMAIN are two different variables in php programming .

$domain = "";
        echo "$DOMAIN";

 When you run the above PHP programme you will get an error massage like ( Notice: Undefined variable: DOMAIN in C:\xampp\htdocs\dmbtest\variable.php on line 4 )


For more details, Please refer the PHP manual and the W3Schools web site.

If you have found  what you expected please comment and like on our facebook page