php copying array elements by value, not by reference

前端 未结 6 2008
清歌不尽
清歌不尽 2020-12-06 05:48

I have the following code:

$data[\'x\'] = $this->x->getResults();  

$data[\'y\'] = $data[\'x\'];

//some code here to modify $data[\'y\']
//this cause         


        
6条回答
  •  渐次进展
    2020-12-06 06:22

    I just discovered that if you simply want a copy of an array of values (no references) from a constant then you can just write:

    $new_array = (array) (object) self::old_array;

    Not an exact answer to the OP's question but it helped me and might help someone else.

提交回复
热议问题