An array a itself is referenced by other arrays. Now I want to assign array a to array b in an if judgment, but I don’t want to assign the reference in a to b, I just want to simply pass the value. , how to do this? Because we only want to change the value of b in the if, we judge that the value of a outside cannot be changed
Write an example, the text description seems a bit convoluted
"Assign array a to array b in an if judgment", do you assign array a to array b, or array b to array a?
Assign array a to array b
Assign array b to array a
Just assign the value of
directlyb=a
就好了,在php
中数组不加&符号都是值传递,所以if
里面就算b
变化了,也不会影响a
It won’t change, because a is assigned by reference, which is no problem, but as long as a and b are passed by value, they will not have a reference relationship. You didn’t read the code. I tried to simulate a comparison based on your needs. Simple scenario, you can try running it yourself:
As long as you are here
$b=$a
之前加一句unset($val)
;