PHP remove “reference” from a variable.

后端 未结 4 2104
旧巷少年郎
旧巷少年郎 2021-01-11 14:18

I have the code below. I want to change $b to use it again with values. If I do so it changes $a as well. How can I assign a value to $b again after previously assigning it

4条回答
  •  青春惊慌失措
    2021-01-11 14:36

    First of all: Creating a reference from $a to $b creates a connection (for the lack of a better word) between the two variables, so $a changing when $b changes is exactly the way it is meant to work.

    So, assuming you want to break the reference, the easiest way ist

    unset($b);
    $b="new value";
    

提交回复
热议问题