Ec (2); closely connected to PHP variables, constant learning notes (read notes from the PHP manual) a dollar sign ($) in PHP followed by a variable name, that is, a variable. Variable names are case sensitive. The variable name can start with a number or underline. In PHP3, values are always assigned to values of variables. PHP4 provides another way to assign values to variables: assign values to input addresses. Assign values using the transfer address, that is, simply append a (& amp;) symbol to the variable to be assigned before "script" ec (2); "script"
Keep in touch with PHP variables and constant learning notes (read notes from the PHP manual)
In PHP, a dollar sign ($) is followed by a variable name, that is, a variable. Variable names are case sensitive. Variable name
Allow numbers or underscores.
Assignment of variable transfer addresses
In PHP 3, values are always assigned to variables. PHP 4 provides another way to assign values to variables: assign values to input addresses. Use
Transfer address assignment, That is, simply
Append a (&) symbol to the variable to be assigned a value.(Source variable ). This means that the new variable simply references the original variable,
Changing new variables will affect the original variables.And vice versa.
$ Foo = ''bob '';
$ Bar = & $ foo;
$ Bar = "My name is $ bar ";
Echo $ bar;
Echo $ foo;
?>
|
The foo variable is assigned only to the first line. Normally, it should be output as "Bob". However, the address is assigned to the variable bar. When the value of the variable bar changes, the value of the foo variable also changes.
About (Super) global variables
PHP global variables are declared when variables are referenced, rather than global or local variables when variables are defined at the first line of the program and assigned values.
$ A = 1;
$ B = 2;
Function Sum ()
{
Global $ a, $ B;
$ B = $ a + $ B;
}
Sum ();
Echo $ B;
?>
|
If global variables are not declared in Sum (), the program reports an error for undefined variables.
Of course, some variables in PHP do not require global declaration within the scope of a program. These variables are called
Super global variableThese super global variables are not user-defined, but some predefined PHP variables, such as $ _ GET, $ _ POST, and $ _ COOKIE.
Variable
Variables that are interesting in PHP, such as $ a = "bruce", can also be represented as $ bruce using $ a, that is, variables are two dollar symbols used.
But in $ a [1], is $ a [1] a variable, or is $ a used as a variable and the value cited as [1] In this variable retrieved?
There is no sequential relationship between the two.Instead, $ {$ a [1]} or $ {$ a} [1] is used to represent the preceding two cases.
========================================================== ========================
Constant
A constant is different from a variable, and its range is global.
By default, constant identifiers are case sensitive.
No dollar sign before a constant ($)
Once defined, a constant cannot be redefined or undefined.
Constants can only be defined using the define () function, but cannot be defined using the value assignment statement.
For example, define ("MYNAME", "cnbruce") defines a MYNAME constant with a value of "cnbruce ".
Define ("MYNAME", "cnbruce ");
$ MYNAME = "cnrose ";
Echo MYNAME;
Echo $ MYNAME;
? |