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);
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'
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!