PHP4 User manual: Variables-Basics

Source: Internet
Author: User
Tags regular expression variable scope
DIV class=chapter>
Directory listings
Basis
Fixed variable
Variable scope
Variable for variables
Variables outside of PHP
Description of the variable: in PHP is the name of a dollar end-of-file following variable. Variable names are case sensitive.
The name of the variable is the same as the other tags in PHP. A valid variable name starts with a word line or underscore, followed by some lines, numbers, or underscores. Treated as a regular expression, it would be like this: ' [a-za-z_x7f-xff][a-za-z0-9_x7f-xff]* '
Note: One letter is a-Z, A-Z, and the ASCII character 127 through 255 (0X7F-0XFF).


$var = "Bob";
$Var = "Joe";
echo "$var, $Var"; Output "Bob, Joe"
$4site = ' not yet '; Error The beginning cannot be a number
$_4site = ' not yet '; Effective The beginning can be underlined
$t äyte = ' Mansikka '; Valid: ' Ä ' is ASCII 228.

In PHP 3, a variable is assigned by its value. 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 assigning a variable's value to another variable, only changing the value of those variables does not affect the other variables. See expressions for more information.
PHP 4 provides another way to assign values to variables: reference assignments. This means that the new variable is simply referencing the original variable (this new variable is just a "pseudonym" or "point") changing the new variable will affect the original variable, and vice versa. This also means that no replication is performed: Therefore, the allocation rate is faster. However, such acceleration is only reflected in complex loops or the allocation of large arrays and objects.
Assign a reference, just the variable that is assigned (the source variable) before adding the "&" number. For example, the following code fragment outputs ' My name is Bob ' two times:

<?php
$foo = ' Bob '; Assign value ' Bob ' to $foo
$bar = & $foo; Reference $foo by $bar.
$bar = "My name is $bar"; Change the $bar ...
Echo $foo; $foo have also been changed.
Echo $bar;
?>

One important hint: only one variable that is specified can be assigned by reference.

<?php
$foo = 25;
$bar = & $foo; This is a valid assignment.
$bar = & (24 * 7); Error: Reference to an unnamed expression.
function test ()
{
return 25;
}
$bar = &test (); Error.
?>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.