<?php
$o1 = new stdClass;
$a = 'd';
//This is the base array or the initial structure
$o1->ar1 = ['a', 'b', ['ca', 'cb']];
$o1->ar1[3] = & $a; //set 3rd offset to reference $a
//direct copy (not passed by reference)
$o1->ar2 = $o1->ar1; //alternatively array_replace($o1->ar1, []);
$o1->ar1[0] = 'z'; //set offset 0 of ar1 = z do not change ar2
$o1->ar1[3] = 'e'; //$a = e (changes value of 3rd offset to e in ar1 and ar2)
//copy and remove reference to 3rd offset of ar1 and change 2nd offset to a new array
$o1->ar3 = array_replace($o1->ar1, [2 => ['aa'], 3 => 'd']);
//maintain original array of the 2nd offset in ar1 and change the value at offset 0
//also remove reference of the 2nd offset
//note: offset 3 and 2 are transposed
$o1->ar4 = array_replace_recursive($o1->ar1, [3 => 'f', 2 => ['bb']]);
PD9waHAgCgokbzEgPSBuZXcgc3RkQ2xhc3M7CiRhID0gJ2QnOwovL1RoaXMgaXMgdGhlIGJhc2UgYXJyYXkgb3IgdGhlIGluaXRpYWwgc3RydWN0dXJlCiRvMS0+YXIxID0gWydhJywgJ2InLCBbJ2NhJywgJ2NiJ11dOwokbzEtPmFyMVszXSA9ICYgJGE7IC8vc2V0IDNyZCBvZmZzZXQgdG8gcmVmZXJlbmNlICRhCgovL2RpcmVjdCBjb3B5IChub3QgcGFzc2VkIGJ5IHJlZmVyZW5jZSkKJG8xLT5hcjIgPSAkbzEtPmFyMTsgLy9hbHRlcm5hdGl2ZWx5IGFycmF5X3JlcGxhY2UoJG8xLT5hcjEsIFtdKTsKJG8xLT5hcjFbMF0gPSAneic7IC8vc2V0IG9mZnNldCAwIG9mIGFyMSA9IHogZG8gbm90IGNoYW5nZSBhcjIKJG8xLT5hcjFbM10gPSAnZSc7IC8vJGEgPSBlIChjaGFuZ2VzIHZhbHVlIG9mIDNyZCBvZmZzZXQgdG8gZSBpbiBhcjEgYW5kIGFyMikKCi8vY29weSBhbmQgcmVtb3ZlIHJlZmVyZW5jZSB0byAzcmQgb2Zmc2V0IG9mIGFyMSB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