|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-05-11 05:55 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 22:00:01 2025 UTC |
unset in function doesn't work on global arrays example: <?php { function ListIt() { global $ar; if (is_array($ar)) { foreach($ar as $k => $v) { echo "ar[$k] = $v <br>\n"; } } else { echo "empty/nonarray <br>\n"; } echo "<br>\n"; } function UnsetOne($i) { global $ar; unset($ar[$i]); } function UnsetAll() { global $ar; //echo "t1s: <br>\n"; ListIt(); echo ":t1e <br>\n"; unset($ar); //echo "t2s: <br>\n"; ListIt(); echo ":t2e <br>\n"; } echo "init: <br>\n"; $ar = array(); $ar[1] = "a"; $ar[2] = "b"; $ar[3] = "c"; $ar[4] = "d"; ListIt(); echo "unset 3: <br>\n"; UnsetOne(3); ListIt(); echo "unset all (global array in function): <br>\n"; UnsetAll(); ListIt(); echo "unset all (top level): <br>\n"; unset($ar); ListIt(); } ?>