I would like to copy an array item that contains an object.
$arr = [
'first_item' => [
'label' => 'a',
'date' => new DateTime('1999-12-30')
],
'second_item' => [
'label' => 'b',
'date' => new DateTime('1999-12-31')
]
];
$copy = $arr['second_item'];
$copy['label'] = 'c'; // OK, does not affect $arr['second_item']
$copy['date']->setDate(2000, 1, 1); // changes $arr['second_item'] as well
Just out of ideas, I tried to replace $copy = $arr['second_item']
by $copy = clone $arr['second_item']
but it (understandably) fails with a *"Fatal error: __clone method called on non-object"* message.