note 22455 added to function.array-splice

From: Date: Tue, 18 Jun 2002 23:14:26 +0000
Subject: note 22455 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-31993@lists.php.net to get a copy of this message
Please note that array_splice() 's second argument is an OFFSET and not an INDEX. Lets say you want to $array_of_items = array ('nothing','myitem','hisitem','heritem'); $sid = array_search('myitem',$array_of_items); echo $sid; /* prints out 1, since index element 1 is "myitem" */ Now, lets say we want to remove that "myitem" from the array: $array_of_items = array_splice($array_of_items,(1+$sid),1); Notice how you have to add a one to the $sid variable? That is because offset item 1 is "nothing" and since $sid is currently 1 (the index of "myitem"), we add 1 more to it to find out its OFFSET. DO NOT DO THIS: $array_of_items = array_splice($array_of_items,$sid,1); -- http://www.php.net/manual/en/function.array-splice.php http://master.php.net/manage/user-notes.php?action=edit+22455 http://master.php.net/manage/user-notes.php?action=delete+22455 http://master.php.net/manage/user-notes.php?action=reject+22455

« previous php.notes (#31993) next »