Is there a function to make a copy of a PHP array to another?

前端 未结 19 2241
我寻月下人不归
我寻月下人不归 2020-12-07 06:44

Is there a function to make a copy of a PHP array to another?

I have been burned a few times trying to copy PHP arrays. I want to copy an array defined inside an obj

19条回答
  •  旧巷少年郎
    2020-12-07 07:37

    PHP will copy the array by default. References in PHP have to be explicit.

    $a = array(1,2);
    $b = $a; // $b will be a different array
    $c = &$a; // $c will be a reference to $a
    

提交回复
热议问题