What is Variable?
Variables are known to hold data that can change during runtime of a program.
The following are few important factor about PHP variables
-
A PHP variable should declared using a dollar sign followed by variable name.
- A variable name can start with an underscore or with a letter.
- PHP variables are case sensitive .So, $Web is not the same as $web.
Naming convention
Similar to other programming language such as C and C++, PHP
also fallows a
naming convention that should be used while declaring
variables. Consider the fallowing example
$myVal = "My First Variable";
The above examples
shows the naming convention used in PHP to declare a variable:
-
The dollar sign: In PHP, each variable that you declared should
begin with a dollar sign.
-
Variable name: It is always advisable to choose meaningful
variable names. Which will help developers to understand why the
variable was declared and where it can be used. For example, if you use
the variable name $u for User name and $e for User email address then
you may misinterpret it at a latter stage. So, when you start using
PHP or any other programming languages you should use meaningful
variable names.
-
Operator : The equal sign is an operator that assigns a value to
the variables.
-
Data type (value assigned to a variable): The string
"My First Variable" is the value that
assign to the variable $myVal.
Variables are assigned using values. These value can be of
Boolean, integer, float, or string type. Once declared, variables can be
referenced in a script.