The difference between passing by value and reference in PHP

(*-*)浩
Release: 2023-02-26 13:22:02
Original
2923 people have browsed it

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 ), only two different memory spaces appear 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. (Recommended learning: PHP video tutorial)

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

Quote

Quote is to copy the reference of the variable (new The 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

The above is the detailed content of 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:
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