PHP4 User Manual: Variable -> Foundation

zhaozj2021-02-08  224

Chapter 7. Variables

Directory list

basis

Fixed variable

Variable scope

Variable variable

Variables outside PHP

basis

Variable Description: The name of the variable after a dollar in PHP. Variable names are case sensitive.

Naming of the variable name is consistent with other tags in PHP. A valid variable name begins with a word line or a downline, followed by some word lines, numbers, or underscores. It will be like this as a regular expression, it will be like this: '[A-ZA-Z_ / X7F- / XFF] [A-ZA-Z0-9_ / X7F- / XFF] *'

Note: A letter is A-Z, A-Z, and ASCII characters 127 THROUGH 255 (0x7F-0xFF).

$ VAR = "bob";

$ VAR = "Joe";

Echo "$ VAR, $ VAR"; // Output "Bob, Joe"

$ 4SITE = 'not yet'; // error; start can't be a number

$ _4site = 'not yet'; // is valid; starting can be underscore

$ täyte = 'mansikka'; // Valid: 'Ä' is ASCII 228.

In PHP 3, the variable is assigned. In other words, when you assign an expression to a variable, the value of the original expression is copied to the destination variable.

This means that allocating a variable value to another variable, only to change the value of those variables does not affect other variables. See Expressions for more information.

PHP 4 provides additional ways to variable allocation values: reference assignment. This means that the new variable is a simple reference raw variable (this new variable is just a "pseudonym" or "pointing") change the new variable will affect the original variable, and vice versa. This also means that no replication is performed: Therefore, the distribution is faster. Despite this, such acceleration is only reflected in complex cyclic or distribution of large arrays and objects.

Assign a reference, just before the variable of the assigned (source variable) is added to "&". For example, the following code snippet outputs 'my name is bob' twice:

$ foo = 'bob'; // Assign value 'bob' to $ foo

$ bar = & $ foo; // Reference $ foo by $ bar.

$ bar = "my name is $ bar"; // Change $ BAR ...

Echo $ foo; // $ foo is also changed.

Echo $ bar;

?>

An important tip: Only one specified variable can be assigned.

$ foo = 25;

$ bar = & $ foo; // This is a valid allocation.

$ BAR = & (24 * 7); // Error: References that have no named expressions.

Function test ()

{

Return 25;

}

$ bar = & test (); // Error.

?>

转载请注明原文地址:https://www.9cbs.com/read-3443.html

New Post(0)