When calling a function, assign the PHP array as an actual parameter to the formal parameter, and modifying it in the function will not affect the array itself.
Explain that the transfer in this process is by value. The array variable is not a reference to the array itself. The PHP array itself exists in the form of a value, and the formal parameter is a copy of the array.
This is very different from other languages (such as c, Js, etc.), so it’s worth noting!
Copy code 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 )
Js code is as follows:
Copy code 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 "]
http://www.bkjia.com/PHPjc/326508.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326508.htmlTechArticleWhen calling a function, by assigning the PHP array as an actual parameter to the formal parameter and modifying it in the function, it will not affects the array itself. Note that the transfer in this process is by value, and the array variable does not refer to...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn