PHP传参之传值与传址的区别_PHP教程

WBOY
Release: 2016-07-13 09:56:15
Original
783 people have browsed it

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

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

        这篇文章主要介绍了PHP传参之传值与传址的区别,十分的简单,大家通过实例简单对比下就明白了,有需要的小伙伴可以参考下。

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

  ?

1

2

3

function test(&val){

return $val;

}

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

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

  ?

1

2

3

4

5

6

7

$test = "hello";

function myFun(&$val){

$val = "hello world";

return $val;

}

echo myFun(&$test); //hello world

echo $test; //hello world

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

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/989554.htmlTechArticlePHP传参之传值与传址的区别 PHP传参之传值与传址的区别 这篇文章主要介绍了PHP传参之传值与传址的区别,十分的简单,大家通过实例简单...
Related labels:
php
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!