I have the following function which unset array element's property. During this process, it also unsets from the original array.
Is there any way to update the array element without effecting the original array?
private function AccumulateRoles($Roles) {
$RoleArray = [];
foreach($Roles as $key => &$Role) {
array_push($RoleArray, $Role);
if(isset($RoleArray[$key]->children)) {
unset($RoleArray[$key]->children); // This effects $Role also.
}
}
}
unset($RoleArray[$key]->children); // This effects $Role also.
I don't want to change $Role