In PHP 3, variables are always assigned values. PHP 4 provides another way to assign a value to a variable: to send an address assignment. Using a pass address assignment, simply appends a (&) symbol to the variable that will be assigned the value (the source variable). This means that the new variable simply references the original variable, and changing the new variable will affect the original variable, and vice versa.
<?php
$foo = ' Bob ';
$bar = & $foo;
$bar = "My name is $bar";
Echo $bar;
Echo $foo;
?>
Variable foo is only assigned in the first row and normally output as "Bob", however, the value of variable foo changes as the variable bar value changes, but the assignment is assigned to the variable bar.
About (super) global variables
The declaration of a PHP global variable is declared when the variable is referenced, not as a global or a local variable when the first line of the program is defined or assigned.
<?php
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>
If the global variable is not declared using global in the function sum (), the program complains about the undefined variable.
Of course, there are some variables in PHP in the scope of a program does not need the global declaration, these variables are called super Global variables, and these hyper-global variables are basically not user-defined, but some PHP predefined variables, such as $_get, $_post, $_cookie, and so on.
About variable variables
The more interesting variable variables in PHP, such as $a = "Bruce", can also be expressed as $bruce by using $ $a, variable is the two dollar sign used.
But in $ $a [1], is $a [1] as a variable, or $ $a as a variable and take out the value indexed by [1] in that variable? There is no sequential relationship here, but instead uses ${$a [1]} or ${$a}[1] to represent both of these situations.
In addition, how to output a constant and a value of a variable, which involves a string operation of PHP, uses the English period (.) to combine string concatenation into a new string, similar to the & in ASP.
echo myname. ",". $MYNAME; Output is "Cnbruce,cnrose"
Like predefined variables in a variable, PHP also has predefined constants (or magic constants) that do not require the define () function definition. Like what
__FILE__ represents the full path and file name of the file, similar to the Server.MapPath current file in ASP
<?php
Echo __file__;
?>
PHP predefined constants are divided into:
Kernel predefined constants, constants defined in the PHP kernel, Zend, and SAPI modules
Standard predefined constants, default defined constants in PHP
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.