Here is the php code:
$options_schools = array();
$options_schools_deepcopy = array();
if (!empty($schools) && is_array($schools)) {
foreach ($schools as $key => $val) {
$temp_school = $key;
$options_schools[$temp_school]=$key;
}
$options_schools_deepcopy= $options_schools;
}
echo form_dropdown('school', $options_schools_deepcopy, '');
I want the array $options_schools_deepcopy
to bear the deep copy values of array $options_schools
with no reference to it. So, somewhere in the code when array $options_schools
becomes null, $options_schools_deepcopy
should still have the values originally copied from $options_schools
irrespective of where it is accessed in the code. How to achieve it?
Edit1: Please note: As you see from my code, I am trying to make a copy of an array $a into $b while in a if-else condition. I want $b to have the same value of array $a which is assigned when if-else was satisfied. I want $b to retain the copied array anywhere in the code irrespective of it satisfies if-else condition or not and also no matter how array $a changes.
Edit2: if-else does become true but only at a certain point of the code and that is when $options_schools has all the values I need to get copied to $options_schools_deepcopy.