PHP Variables

By August 19, 2015PHP

Variables are used to store information or a value to its like in text of string, numbers, etc. Like other programming languages PHP have its own variables. But in PHP there is no need to define there data type.


In PHP variables are define by a dollar sign follow by the name of the variables. The variables name is case-sensitive i.e.

$a, $abc etc.

The first character after $ must be character or underscore. The remaining character in name may be letter , number or underscore.

Syntax :

$variable_name = value;
$c= $a+$b;
echo $c  // output 30

$a = "Pankaj";
$b= "Sugara";

echo "$a , $b"; //Output Pankaj Sugara

In PHP, variables are always assigned by values. PHP also offers another way to assign the valyue by refrece. Blew are the examples of assign by value and assigh by refernce in PHP

$var1 = "India"; // this is assign by value to variable
$var2 = &$var1; // this is refrence $var1 by $var2

echo $var2; // Output : India
echo $var1; // Outut : India
Pankaj Singh Sugara

Author Pankaj Singh Sugara

Experienced Software Engineer with a demonstrated history of working in the marketing and advertising industry. Skilled in SQL, Web Applications, PHP, WordPress, and Joomla. Strong engineering professional with a B-TECH focused in Information Technology from JCDM College of Engineering Sirsa, Haryana.

More posts by Pankaj Singh Sugara