PHP array transfer is a value transfer instead of a reference transfer concept to correct

Source: Internet
Author: User

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.

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!
Copy codeThe 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:
Copy codeThe 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"]

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.