Front-end PHP entry -014-parameters Reference

Source: Internet
Author: User
Tags ord

We have learned the references to variables, so let's review the Knowledge:

  
 
  1. <?php
  2. $a = 10;
  3. $b = &$a;
  4. $a = 100;
  5. echo $a.‘---------‘.$b;
  6. ?>

Instead, the parameter reference of the function points to the same position as the formal parameter and the argument. If the parameter changes in the function body, the value of the argument also changes. Let's go through the experiment to see:

  
 
  1. <?php
  2. $foo = 100;
  3. //注意:在$n前面加上了&符
  4. function demo(&$n){
  5. $n = 10;
  6. return $n + $n;
  7. }
  8. echo demo($foo).‘<br />‘;
  9. //你会发生$foo的值变为了10
  10. echo $foo;
  11. ?>

Using the example above, we find that the argument is F oo,in theTunewithd emoof thewhenHou,Let f o , in tune When using the D e m o wait , let Foo and Nmeanstoto thethewithaaSaveStorageAreaDomain,when N /mi> means to /mo> to The with one x save store zone field , when When the value of n is changed. Then the value of $foo is changed.



From for notes (Wiz)

Front-end PHP entry -014-parameters Reference

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.