The variable is seen here as a container, which you can use to store data information. It doesn’t make any difference to him, so it becomes easy to learn php.
Type of variable:-
- -Local variable
- -Global variable
- -Static variable
The variable has to start with a $ sign, and you have to type a name with it. By combining these two, it will be called a variable of php.
Ex: $roll $price $name
When you write the variable name, What is the rule, and what should be kept in mind?
Variable names must always start with $.
- The first word after the $ sign must be either a letter or an underscore(_).
- Variable names will not start with numbers. The number cannot be given after the $ sign. Can give any letter or underscore.
- A variable name that is case-sensitive. This means that num you have written in small and NUM you have written in the capital will be considered different and will not be considered the same.
- You cannot put a predefined constant in a variable name, such as PHP_VERSION, PHP_OS is a predefined constant.
Whenever you write a variable name, it does not know what kind of data will be kept in it or what kind of data this variable has to hold. It is not known to that variable, but as soon as you assign the value, that variable automatically understands the data tag. If someone assigns an integer value to that variable, then that variable understands that my data type is an integer. If someone assigns a string, then it understands that my data type is a string.
If you declare any variable in php, it is always assigned before using it. This means you have not given value to any variable and if you want to assess then it will not be assessed.
So keep in mind that whenever you are evaluating a variable in php its value must be already assigned.
Ex:- $roll=265; $price= 25.50; $name="geeky shows";
<?php $roll = 565; echo $roll; ?>
Can write in numeric without even a column
<?php $roll = "name"; echo $roll; ?>
But always write the name with a semi-column.