PHP Variables


Variables are “containers” for storing information.

Creating (Declaring) Variables

[sam id=”4″ codes=”true”]


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

[message_box color=”yellow”]




$txt=”Hello Engineers!!”;



echo $txt;

echo “<br>”;

echo $x;

echo “<br>”;

echo $y;





After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 6.5.

Note:- when you assign text value to variable,puts quotes around the value


PHP Variables

A variables can have sort name (like x and y) or one more descriptive names (age,total,value).

Rules for PHP variables:

  • A Variable start with $ sign followed by the name of the variable
  • A Variable start with letter or underscore character
  • A Variable can not start with a number
  • A Variable can not contain alpha-numeric character and underscores (A-z ,0-9,and _ )
  • Variable names are case sensative ($age and AGE are two different variable)

Remember  that php variables names are case sensative !!!



Previous articlePHP Syntax
Next articlePHP Variable Scopes
I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.

Leave a Reply

Please Login to comment
Notify of