how do "really" clear a global PHP array -
note: seems wrong happening, , there no issue using $a = array();
. since assignments arrays copy. (i had thought there accesses reference causing problems - typo. i've added details answer below.
i've got php looks this:
$myarray = array(); function usearray() { global $myarray; // ... myarray ... } function cleararray() { global $myarray; // ... somehow clear global array ... }
i know sucks design viewpoint, it's required work around third-party code can't change...
my question can put in cleararray
function make work? the usual advice of using guess loop on keys in array , unset each in turn - this:$myarray=array();
or unset($myarray);
don't work since change local version, not global version.
function cleararray() { global $myarray; foreach($key in array_keys($myarray) ) { unset( $myarray[$key] ); } }
but seems hacky , unclear. there better solution?
the usual advice of using $myarray=array();
or does work.unset($myarray);
Comments
Post a Comment