Hello everyone Today i am going to explain about variable. If you have ever gone through any programming language or algebra you might have heard about it. Lets discuss over it.
What is variable : A variable is a value or entity which can be changed depending upon the conditions or information passed through it. In other words, A variable is an element or factor which can be changed. varible is not fixed.
In simplest term, Think variable is a container which holds something for you that can be used later on. Like cold drink bottle. You can replace cold drink with water, or other stuffs when required.
Why we use variables : Variable is used to store the value, values can be string(hello Php), integer (4,6,7..).
- Re-usability of code (Once a variable is declared we can use it multiple times).
- Minimize code length : After assigning value to a variable we can use it multiple time. No need to write codes multiple times.
How to declare a variable : In Php you can define a variable as –
$fruit = “mango”;
$car = ‘audi’;
$value = 4;
*Note : $ signs are mandatory to be placed before any variable name. It is most common mistake done by beginners. If you forgot to mentions $ sign, Your Php programme will not run.
Lets take an example to demonstrate how to declare a variable and use in our programme.
$fruit = "mango"; // Assigning mango inside fruit variable.
$Car = 'audi'; // Assigning value audi inside car variable.
$value4 = 4;
$value_float = 4.5;
A variable can be defined in any of the following ways. Keep in mind that PHP variables are case-sensitive i.e. $fruid is different than $Fruit.
echo $Value = "capital V";
echo "<br>"; // <br> is used to line break (print in next line).
echo $value = "small v";
Tips : In Php we can initialize variable before declaring it. Variable declaration does not require to initialize it.