clone

Definition

1
Arr::clone(array $array): array
Copied!

Description

Copy array and clone every object inside it

Examples

1
$object = new class() {
2
public $counter = 1;
3
4
function __clone()
5
{
6
$this->counter = 2;
7
}
8
};
9
10
$array = [
11
'foo',
12
'bar',
13
$object,
14
'test',
15
'nested' => [
16
'object' => $object
17
]
18
];
19
20
$cloned = Arr::clone($array);
21
22
$cloned[0] -> 'foo'
23
$cloned[2]->counter -> 2
24
$cloned['nested']['object']->counter -> 2
Copied!
Last modified 2yr ago
Copy link