Variables are "stores" for storing information.this is simple definition
are you remember Mathematical equations that we study in the school
a=5 s=7 q=a+s These letters are called variables
ii give you simple example if we have store Contains computer ,laptop , mobile phone ok
this store have name store a which easy to say store a or say his all Contents
there is many reasons to use Variables and i will give you some in it
how can we write Variables in php
Variables in PHP starts with a $ sign, followed by the name of the variable example ($test)
The variable name must begin with a letter or the underscore character "_" example ($_test or $test)
A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
A variable name should not contain spaces
Variable names are case sensitive (z and Z are two different variables)
variables is created when you give a value to it
example
<?php
$var=55;
echo $var ;
echo"<br>";
$var1=66;
echo $var+$var1;
$var_text= " hi every body";
echo $var_text;
?>
result
55
121hi every body
remember When we assign a text value to a variable, put quotes around the value. like $var_text.
PHP is a Loosely Typed Language
In PHP, a variable does not need to be declared before adding a value to it.In the example above, notice that we did not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on its value.
In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it.