PHP数组传递是值传递而非引用传递概念纠正
在调用函数时通过将PHP数组作为实参赋给形参,在函数中修改,并不会影响到数组本身。
说明此过程中的传递为值传递,数组变量并非是指向此数组本身的引用,PHP数组本身以值的形式存在,同时形参是对数组的拷贝。
这点与其他一些语言不同(如c、Js等)很不相同,值得注意!
复制代码 代码如下:
$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代码如下:
复制代码 代码如下:
var arr = new Array('corn', '24');
test_arr(arr);
function test_arr(arr){
arr[0] = 'qqyumidi';
}
console.log(arr); //result:["qqyumidi", "24"]

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment