PHP array passing is value passing and not reference passing concept correction _php Tutorial

Source: Internet
Author: User
When a function is called, it is modified in the function by assigning the PHP array as an argument to the parameter, without affecting the array itself.

Note that the pass in this procedure 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 parameter is a copy of an array.

This is different from some other languages (such as C, JS, etc.) is not the same, 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"]

http://www.bkjia.com/PHPjc/326508.html www.bkjia.com true http://www.bkjia.com/PHPjc/326508.html techarticle when a function is called, it is modified in the function by assigning the PHP array as an argument to the parameter, without affecting the array itself. Note that the pass in this procedure is passed as a value, and the array variable does not refer to ...

  • Related Article

    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.