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

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

    Creates a copy of the ArrayObject

     1, "oranges" => 4, "bananas" => 5, "apples" => 10);
    
    $fruitsArrayObject = new ArrayObject($fruits);
    $fruitsArrayObject['pears'] = 4;
    
    // create a copy of the array
    $copy = $fruitsArrayObject->getArrayCopy();
    print_r($copy);
    
    ?>
    

    from https://www.php.net/manual/en/arrayobject.getarraycopy.php

提交回复
热议问题