// given following array:
$data = array(
0=>array(
"data"=>"object1",
"col"=>array(
0=>array(
"data"=>"object2",
"col"=>array(
0=>array(
"data"=>"object3",
),
1=>array(
"data"=>"object4",
),
)
),
1=>array(
"data"=>"object5",
"col"=>array()
),
)
)
);
// A new object can be added or existing one replaced given a position of any length // array(0), array(1,0), array(1,0,0), etc...
$data = add($data, array(0,0,1), "new_object");
function add($data, $position, $object) {
// this has to be produced based the location:
$data[0]["col"][0]["col"][1]["data"] = "new_object";
return $data;
}
//Is there a sane way to do it in php5 besides creating $data."[0][\"col\"][0][\"col\"][1][\"data\"]"?
//Thanks for any hints!