What is the definition of PHP variables and how PHP works?

Source: Internet
Author: User
This article is shared with you about how PHP variables are defined and how PHP works, the content is very useful, and I hope to help small partners in need.

1. Variable definition:

It is common to learn that a variable represents a storage space and an "identifier" for its data.

Variable name point to variable value

In more depth, a piece of area where the variable points to memory

2, the variable working principle, through the drawing analysis method--memory space

<?php//php reference variable: Different variable names point to the same address. Defines a variable a, at which time the memory opens up an area $a points to that area.    $a = 100;var_dump ($a); int 100//defines variable B and assigns the value of a variable to B, where there are two variables ($a and $b) pointing to the range.    $b = $a; Var_dump ($b); int 100//modifies the value of the $ A variable, and the PHP variable has the property of copy on write, so the region value pointed to by a is copied and rewritten, and A and B point to different regions respectively.    $a = 10;var_dump ($a);    int 10var_dump ($b); int 100//------------------------------------------------------------------$c =: $d = & $c; $c = 10;var_dump ($    c);    int 10var_dump ($d); int 10//When a reference is directed, the PHP variable does not have a cow attribute and points to the same memory area.    * unset () can only eliminate the variable reference, cannot delete its memory allocation space//------------------------------------------------------------------/* Example:    Write the output of the following program: <?php $data = [' A ', ' B ', ' C '];    foreach ($data as $key = + $val) {$val = & $data [$key]; Q: What is the value of the final $data?    */$data = [' A ', ' B ', ' C '];        foreach ($data as $key = + $val) {$val = & $data [$key];    Print_r ($data); }/* 1. $key = 0, $val = ' a ', $val = & $d [0] = ' a ' $data = [' A ', ' B ', ' C '];2. $key = 1, $val = ' B ' , = = $d [0] $val = &AMP; $d [1] = ' B ' $data = [' B ', ' B ', ' C '];1. $key = 2, $val = ' c ', = = ' = ' 1] $d = & $val [2]=> ' C ' $ data = [' B ', ' C ', ' C ']; */

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.