The following will not work:
unset($siteMapEntries); $siteMapEntries = array();Read on to see the solution.
Solution
The solution is to use unset() and the $GLOBALS array in the following way to clear $siteMapEntries values by reference:
unset($GLOBALS['siteMapEntries']);
The following PHP code illustrates how to empty a global array by reference:
<?php $siteMapEntries = array(); function deleteSiteMapEntries(){ unset($GLOBALS['siteMapEntries']); global $siteMapEntries; $siteMapEntries = array(); } function addASiteMapEntry($loc, $priority){ global $siteMapEntries; $siteMapEntries[] = array( 'loc' => $loc, 'priority' => $priority ); } addASiteMapEntry('http://www.chtoen.com/','1.0'); echo "size before: ".count($siteMapEntries)."<br/>"; deleteSiteMapEntries(); echo "size after: ".count($siteMapEntries)."<br/>"; ?>Questions? Let me know!