Home > php教程 > php手册 > PHP传参之传值与传址的区别,php传参

PHP传参之传值与传址的区别,php传参

WBOY
Release: 2016-06-13 09:06:06
Original
961 people have browsed it

PHP传参之传值与传址的区别,php传参

废话不多说,先来看段代码

function test(&val){
return $val;
}
Copy after login

其中为什么用到&进行传参呢,有什么好处?

传址是允许在函数内部进行改变的意思,比如:

$test = "hello";
function myFun(&$val){
$val = "hello world";
return $val;
}
echo myFun(&$test); //hello world
echo $test;         //hello world

Copy after login

以上所述就是本文的全部内容了,希望大家能够喜欢。

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template