#48944 [Opn->Bgs]: unsetting an array does not reindex

From: Date: Thu, 16 Jul 2009 14:00:35 +0000
Subject: #48944 [Opn->Bgs]: unsetting an array does not reindex
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2498@lists.php.net to get a copy of this message
ID: 48944 Updated by: rquadling@php.net Reported By: info at speich dot net -Status: Open +Status: Bogus Bug Type: Documentation problem PHP Version: Irrelevant New Comment: http://docs.php.net/manual/en/language.types.array.php#language.types.ar ray.useful-funcs Note: The unset() function allows removing keys from an array. Be aware that the array will not be reindexed. If a true "remove and shift" behavior is desired, the array can be reindexed using the array_values() function. Previous Comments: ------------------------------------------------------------------------ [2009-07-16 13:14:14] info at speich dot net Sorry, better example: <?php $arr = array(5, 6, 7, 8); print_r($arr); unset($arr[2]); print_r($arr); ?> Output: Array ( [0] => 5 [1] => 6 [2] => 7 [3] => 8 ) Array ( [0] => 5 [1] => 6 [3] => 8 ) ------------------------------------------------------------------------ [2009-07-16 13:11:54] info at speich dot net Description: ------------ I think it would be helpful if the documentation about unset would mention: Unsetting an array item removes it from the array, but does not change the keys. Example: <?php $arr = array(5, 6, 7, 8); print_r($arr); unset($arr[3]); print_r($arr); ?> Output: Array ( [0] => 5 [1] => 6 [2] => 7 [3] => 8 ) Array ( [0] => 5 [1] => 6 [2] => 7 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48944&edit=1

« previous php.doc.bugs (#2498) next »