note 52463 added to function.unset

From: Date: Mon, 02 May 2005 17:47:36 +0000
Subject: note 52463 added to function.unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-88868@lists.php.net to get a copy of this message
If you want to remove a value from the middle of a linear array, you have to use the zero-based integer pointer to it, not the string you want to unset: <?php $a = array("a","b","c","d"); unset($a["b"]); // has no effect var_dump($a); ?> // prints array("a","b","c","d") <?php $a = array("a","b","c","d"); unset($a[1]); var_dump($a); ?> // prints array("a","c","d"); Conversely, if you have an associative array, unset requires the string key: <?php $a = array("a"=>"abc","b"=>"cbs","c"=>"nbc","d"=>"fox"); unset($a[1]); // has no effect var_dump($a); ?> // prints array("a"=>"abc","b"=>"cbs","c"=>"nbc","d"=>"fox") <?php $a = array("a"=>"abc","b"=>"cbs","c"=>"nbc","d"=>"fox"); unset($a["b"]); var_dump($a); ?> // prints array("a"=>"abc","c"=>"nbc","d"=>"fox") ---- Manual Page -- http://www.php.net/manual/en/function.unset.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52463 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52463&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52463&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52463&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52463&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52463&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52463&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88868) next »