We have learned so much about PHP. What is the value transfer method of variables in PHP today? How to deliver? , I wonder if you have fully mastered it. If not, then follow this article to continue learning.
Related recommendations:What are the knowledge points that you must know in PHP? (Second bullet)
The value-passing method of variables:
1, the value-passing method of variables is Refers to the internal detailed form of "passing one variable to another variable" - one-to-one;
2, the value-passing method of variables, there are only 2: value passing, reference passing;
Value transfer:
Sv1= 1;
$v2=Sv1; 1/This is value transfer
Simple understanding: Sv1 Take out the value (note: the value in Sv1 is still there), and then use this value to assign a value to $v2.
Image understanding:
Visible , Value transfer means that the value of variable v1 is copied, and then assigned to another variable v2.
Note:
1The two variables are equal in value at this time1
2The two variables are independent of each other - do not affect each other;
That is, Sv1=10; then echo $v2, //Output 1
The code is as follows:
<?php $v1 =1; $v2 = $v1; //值传递: $v1=10; echo "<br />v2 = $v2";//1 ?>
The running results are as follows:
Pass by reference:
In PHP, there is only one syntax form that can realize the reference-value transfer of variables: the & symbol.
An example is as follows!
$ml=1; $m2 = &$ml; //引用传值方式
Simple understanding: Copy the "reference relationship" between variable $m1 and its data values, and then give it to transaction $m2, that is, at this time , the variable $m2 also has a "reference relationship" (pointing relationship) with the original data,
The result is:
1, at this time there are still 2 variables, but only one Data value (data space), both variables point to this data space.
2. The operation of any of the variables is actually manipulating the data value (space).
<?php $v1 = 1; $v2 = $v1; //值传递: $v1 = 10; echo "<br />v1 = $v1";//10 echo "<br />v2 = $v2";//1 echo "<hr />"; $m1 = 1; $m2 =& $m1;//引用传值方式 $m1 = 10; echo "<br />m1 =$m1";//10 echo "<br />m2 = $m2";//10 ?> </body> </html>
The code is as follows:
Recommended learning: php video tutorial
The above is the detailed content of How to pass values to variables in PHP? How to deliver?. For more information, please follow other related articles on the PHP Chinese website!