Sadly I can't answer the other questions, don't have enough reputation, but I need to point something out that was VERY important for me, and I think it will help other people too.
Unsetting the variable is a nice way, unless you need the reference of the original array!
To make clear what I mean: If you have a function wich uses the reference of the array, for example a sorting function like
function special_sort_my_array(&$array)
{
$temporary_list = create_assoziative_special_list_out_of_array($array);
sort_my_list($temporary_list);
unset($array);
foreach($temporary_list as $k => $v)
{
$array[$k] = $v;
}
}
it is not working! Be careful here, unset
deletes the reference, so the variable $array
is created again and filled correctly, but the values are not accessable from outside the function.
So if you have references, you need to use $array = array()
instead of unset
, even if it is less clean and understandable.