Copy a PHP array item that contains an object -


i copy array item contains 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, not affect $arr['second_item'] $copy['date']->setdate(2000, 1, 1); // changes $arr['second_item'] 

just out of ideas, tried replace $copy = $arr['second_item'] $copy = clone $arr['second_item'] (understandably) fails *"fatal error: __clone method called on non-object"* message.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -