Below is the code that displays "15", why?
function zz(&$x){ $x = $x + 5; } $x = 10; zz($x); echo $x;
Explain, please
you pass the value because the argument is not a direct value of the variable, but passing it by reference, so it gives you 15 as output.
Thank!
It works as it was designed. Using &, you pass $xby reference, which means that everything that the function does with the variable will be done with the original $xone that is set to 10.
&
$x
10
If you used
function zz($x)
$x 10, .
, , , .
, , .
a , $x . .
$x , $x .
"&", , , , , .
.
: .
Just change the original variable and return it again to the same variable name with the assigned new value.
Source: https://habr.com/ru/post/1775848/More articles:include target-specific files - makefilehow to combine multiple true / false rows in MYSQL - mysqlshare env-entry between multiple ejb - javaJQuery Modal Popup Firefox flickering - jqueryClearing JScrollPane, but cannot then "join" tables - javaCan I use iphone API in my web applications? - iphoneJNI CALL change jclass parameter or how to get job from jclass parameter - javaInsert data from Excel into Access using VBA - excel-vbaLength of filtered ArrayCollection in actionscript 3 / flex - flexПредупреждение: fread() [function.fread]: параметр длины должен быть больше 0 - phpAll Articles