What is the difference between passing by value and reference in php?

青灯夜游
Release: 2023-02-28 15:08:02
Original
2283 people have browsed it

What is the difference between passing by value and reference in php?

Passing value

Passing value is to copy the value of the variable to a new value (the value is the same), There are just two different memory spaces in the memory. Assign the new value memory space address to the new variable name. Modifying the values ​​of the two variables has no effect.

$a1 = 234;
$a2 = 34556;
$a1 = $a2;
var_dump($a1,$a2);
$a2 = 'nongjiale.fun';
var_dump($a1,$a2);
Copy after login

Reference

Reference is to copy the reference of the variable (the new reference still points to the original value).

$y1 = 23;
$y2 = 433;
var_dump($y1,$y2);//输出int 23 int 433
$y2 = &$y1;
$y2 = 'mudidi.tech';
var_dump($y1,$y2);//输出string 'mudidi.tech' string 'mudidi.tech'
Copy after login

Recommended learning: PHP video tutorial

The above is the detailed content of What is the difference between passing by value and reference in php?. For more information, please follow other related articles on the PHP Chinese website!

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