Assigning a value to an address for a variable
In PHP 3, variables are always assigned values. PHP 4 provides another way to assign a value to a variable: pass an address assignment. Use a pass-through address assignment, which simply appends a (&) symbol to the variable that will be assigned (the source variable). This means that the new variable simply references the original variable, and altering the new variable will affect the original variable and vice versa.
$foo = ' Bob ';
$bar = & $foo;
$bar = "My name is $bar";
Echo $bar;
Echo $foo;
?>
The variable foo is only assigned in the first row and should normally be output as "Bob", but the value of the variable foo is changed while the value of the variable bar is assigned to the variable bar.
About (super) global variables
The declaration of a PHP global variable is declared when a variable is referenced, rather than defined as a global or local variable when the first line of the program is defined and the variable is assigned.
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>
If the function sum () is not declared globally with global variables, the program will error the undefined variable.
Of course, in PHP there are some variables in the scope of a program does not need the global declaration, these variables are called super-global variables, and these super-global variables are basically not user-defined, but PHP predefined variables, such as $_get, $_post, $_cookie and so on.
About mutable variables
The more interesting mutable variables in PHP, such as $a = "Bruce", can also be expressed as $bruce using $ $a, and variable variables are the two dollar symbols used.
But where in $ $a [1], is $a [1] as a variable, or $ $a as a variable and take out the value of the variable indexed to [1]? There is no back-and-forth relationship, but the two cases are expressed using ${$a [1]} or ${$a}[1].
=========================================================
About constants
Constants are distinguished from variables, which are defined from constants to be global in scope.
The default is case sensitive, which is always uppercase by convention constant identifiers
No dollar sign ($) before constant
Constants cannot be redefined or undefined once defined
Constants can only be defined with the Define () function, not through assignment statements
For example, define ("MYNAME", "cnbruce") is defined as a MYNAME constant with a value of "Cnbruce".
Define ("MYNAME", "cnbruce");
$MYNAME = "Cnrose";
Echo MYNAME;
Echo $MYNAME;
?>
In addition, how to output the constant and variable values together, this requires a string operation involving PHP, using a period (.) to combine string joins into a new string, similar to the & in ASP.
echo MYNAME. ",". $MYNAME; Output as "Cnbruce,cnrose"
Like the 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
Echo __file__;
?>
PHP pre-defined constants are divided into:
Kernel-predefined constants, constants defined in the PHP kernel, Zend, and SAPI modules
Standard predefined constants, constants defined by default in PHP
http://www.bkjia.com/PHPjc/318766.html www.bkjia.com true http://www.bkjia.com/PHPjc/318766.html techarticle The variable is always assigned a value in the address assignment PHP3 of the variable. PHP4 provides another way to assign values to variables: pass-through address assignment. Use a pass-through address assignment, which simply appends a ...