PHP array transfer is a value transfer instead of a reference transfer concept rectification _ PHP Tutorial

Source: Internet
Author: User
PHP array transfer is to correct the concept of value transfer rather than reference transfer. When calling a function, you assign the PHP array as a real parameter to the form parameter. modifying the parameter in the function does not affect the array. It indicates that the value is passed during this process. the array variable does not mean to assign the PHP array as the real parameter to the form parameter when calling the function. modification in the function does not affect the array itself.

This process is passed as a value. The array variable is not a reference to the array itself. The PHP array itself exists as a value and the form parameter is a copy of the array.

This is very different from other languages (such as c and Js). it is worth noting!

The code is as follows:


$ Arr = array (
'Name' => 'corn ',
'Age' => '24 ',
);
Test_arr ($ arr );
Function test_arr ($ arr ){
$ Arr ['name'] = 'qqyumidi ';
}
Print_r ($ arr); // result: Array ([name] => corn [age] => 24)


The Js code is as follows:

The code is as follows:


Var arr = new Array ('corn', '24 ');
Test_arr (arr );
Function test_arr (arr ){
Arr [0] = 'qqyumidi ';
}
Console. log (arr); // result: ["qqyumidi", "24"]

Bytes. It indicates that the value is passed in this process, and the array variable does not mean...

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.