Home > Backend Development > PHP Tutorial > PHP array passing is value passing rather than reference passing concept correction_PHP tutorial

PHP array passing is value passing rather than reference passing concept correction_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:13:24
Original
857 people have browsed it

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

www.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...
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template