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

前端 未结 19 2246
我寻月下人不归
我寻月下人不归 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:34

    In php array, you need to just assign them to other variable to get copy of that array. But first you need to make sure about it's type, whether it is array or arrayObject or stdObject.

    For Simple php array :

    $a = array(
    'data' => 10
    );
    
    $b = $a;
    
    var_dump($b);
    
    output:
    
    array:1 [
      "data" => 10
    ]
    

提交回复
热议问题