note 73117 added to function.unset
| From: | php-general at lists dot php dot net | Date: | Fri, 09 Feb 2007 16:10:02 +0000 |
| Subject: | note 73117 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123177@lists.php.net to get a copy of this message | ||
Just to confirm, USING UNSET CAN DESTROY AN ENTIRE ARRAY. I couldn't find reference to this
anywhere so I decided to write this.
The difference between using unset and using $myarray=array(); to unset is that obviously the array
will just be overwritten and will still exist.
<?php
$myarray=array("Hello","World");
echo $myarray[0].$myarray[1];
unset($myarray);
//$myarray=array();
echo $myarray[0].$myarray[1];
echo $myarray;
?>
Output with unset is:
<?
HelloWorld
Notice: Undefined offset: 0 in C:\webpages\dainsider\myarray.php on line 10
Notice: Undefined offset: 1 in C:\webpages\dainsider\myarray.php on line 10
Output with $myarray=array(); is:
?>
<?
HelloWorld
Notice: Undefined offset: 0 in C:\webpages\dainsider\myarray.php on line 10
Notice: Undefined offset: 1 in C:\webpages\dainsider\myarray.php on line 10
Array
?>
----
Server IP: 64.71.164.2
Probable Submitter: 82.71.67.46
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/73117
Del: integrated -- https://master.php.net/note/delete/73117/integrated
Del: useless -- https://master.php.net/note/delete/73117/useless
Del: bad code -- https://master.php.net/note/delete/73117/bad+code
Del: spam -- https://master.php.net/note/delete/73117/spam
Del: non-english -- https://master.php.net/note/delete/73117/non-english
Del: in docs -- https://master.php.net/note/delete/73117/in+docs
Del: other reasons-- https://master.php.net/note/delete/73117
Reject -- https://master.php.net/note/reject/73117
Search -- https://master.php.net/manage/user-notes.php