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 $myarray=array(); or unset($myarray); don't work since change local version, not global version. guess loop on keys in array , unset each in turn - this:

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 unset($myarray); does work.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -