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"]