Regarding value passing and reference passing, the explanations in books are relatively cumbersome, but they always appear in PHP interviews. Below, I will use a life example to help you understand the difference between them.
Step 1
Suppose we go to a hotel to book a room. We compare the hotel's house number to a variable name, and we use the number of people in the room as the variable name. The process of assignment
Characteristics of value transfer:
1. Value equality
That is, $k1 to $k2 The people in the room are equal.
2. Mutual independence and no influence on each other
That is to say, the number of guests in my $k1 room and the number of guests in my $k2 room do not affect each other. . This is called: "Different ways do not work together."
Second step
Take the above example and assume that our room $k1 is hung up by the maintenance worker with two house numbers $k1 and $k2 to understand
Characteristics of reference passing:
mutual influence, that is to say, how many guests come in $k1, and how many guests are displayed in $k2, which is called "tied on a rope" The grasshopper".
Difference
1. Difference in usage
The symbol passed by the value is =
quote The transfer symbol is &
2. The difference in meaning
Value transfer means that variables are transferred without affecting each other, while reference transfer means that two variables point to the same space. influencing each other.
Recommended tutorial:PHP video tutorial
The above is the detailed content of The difference between php reference and copy. For more information, please follow other related articles on the PHP Chinese website!