What is variable?
A variable is an identifier for a piece of data stored in memory during
the program execution. In PHP, variables are used under basic rules:
A variable name in PHP must be prefixed with a “$” sign. Perl has a
similar rule for scale variables.
Variable names are case sensitive. So $abdul and $Abdul refer to two
different variables.
Variables in PHP are typeless. Therefore there is no variable type
declaration statements in PHP. Any variable can be used as the identifier for
any data type.
& operator returns the reference of a variable.
The reference of a variable can be assigned to a new variable to make an
alias to the original variable.
A variable name can be represented as a string expression. This is
called variable variable name.
Functions define() defines a constant with the constant name and the
constant value.
Only scalar data type values can be used as constant values.
A variable has 2 states: “set” and “unset”. A variable is in the “set”
state, if a piece of data has been assigned to it. A variable is in the “unset”
state, if there is no data assigned to it.
Assignment operations (coded by the assignment operator, =) can be used
to assign data to variables.
The unset ($var) function can be used to remove the assigned data from the
given variable.
Variables can used in any operations like data literals in PHP source
code. If a variable with data assigned is used in an operation, the assigned
data value will be used for the operation. If a variable with no data assigned
is used in an operation, NULL will be used for the operation.
There are some special characters that you should not use them as a part
of a variable name, ‘ ‘, ‘$’, ‘[‘, ‘]’, ‘{‘, ‘}’, …
PHP has a nice built in function, var_dump($var), that prints out
detailed information about the specified variable.
To show you some of variable rules mentioned above, I wrote the PHP
program name Variables.php
Click on the below link to download the file:
PHP Variable
Reviewed by Abdul iTech
on
Tuesday, February 26, 2019
Rating:
No comments: