PHP Variables
Variables in PHP are represented by
a dollar sign followed by the name of the variable.
The variable
name is case-sensitive.
A valid
variable name starts with a letter or underscore, followed by any
number of letters, numbers, or underscores. As a regular expression,
it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
For example;
<?php
$var = 'Potter';
$age= 12;?>
Assign by reference is another way to assign values
to variables. This means that the new variable simply references
(in other words, "becomes an alias for" or "points
to")
the original variable.
Changes to the new variable affect the original,
and vice versa. This also means that no copying is performed; thus,
the assignment happens more quickly.
To assign by reference, simply prepend an ampersand (&) to the
beginning of the variable which is being assigned (the source variable).
<?php
$name = 'Potter'; // Assign the value 'Potter' to $name
$bar = &$name; // Reference $name via $bar.
$name = "My name is $name<br>"; // Alter $name...
echo $name;
echo $bar; // $bar is altered too.
?>
|