php copying array elements by value, not by reference

前端 未结 6 1992
清歌不尽
清歌不尽 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:21

    Not simple. Read about clone

    BUT! if your elements are not objects and not refence type variables you have no problem.

    Example for reference types:

    $v=11;
    $arr[]=&$v;
    

提交回复
热议问题