PHP - Variable Declaration
A PHP variable declaration process is used to declare the variable of type text, number, string, etc. It starts with the $ sign followed by the name of the variable.
A PHP variable declaration process is used to declare the variable of type text, number, string, etc. It starts with the $ sign followed by the name of the variable.
PHP Variable is a container that is used to store information of type string of text, number, boolean, etc. The data stored in the variable can be changed and retrieved when needed.
Every variable is labeled with a meaningful name so that it could be easily understood by a screen reader.
(=)
is used to assign a value to a variable.Followings are the most important rule regarding the variable naming convention.
(A-z, 0-9, and _)
.
PHP
variable names are case-sensitive. Please keep in mind that $age and $Age are two different variables.
In PHP, variable names are case-sensitive. Therefore declaring variable name "learing_resource" is completely different from "learningResources", "learningresources",etc.
Let's see a PHP variable that stores string, integer, and float values.
PHP variables must start with a letter or underscore only.
In, PHP creating a variable is known as declaring variables. Please keep in mind that there is no reserve keyword for declaring PHP variables hence it is known as a loose type language.
=
is known as the assignment operator that is used to assign provided value inside the variable.=
).Please keep in mind that string value is assigned within quotes that will be either single quote or double quote.
PHP variable values can be changed through the source code. Let us understand it with the help of an example.
Basically, reassigning means replacing the new variable value in place of the old value.
The PHP echo statement is used to display output to the screen.
The $var is a normal variable with the name var
that stores any value like string, integer, float, etc. And the $$var
is a variable that stores the value of the $variable inside it.