note 34813 added to function.array-splice

From: Date: Thu, 07 Aug 2003 13:36:15 +0000
Subject: note 34813 added to function.array-splice
Groups: php.notes 
Request: Send a blank email to php-notes+get-53572@lists.php.net to get a copy of this message
If ones need to remove portion of an array by index and preserve keys from dropping and reindexing here is a good start: <?php function my_array_splice(&$_arr, $_index, $_long){ $_keys=array_keys($_arr); $_key=array_search($_index, $_keys); $_keys=array_splice($_keys, $_key, $_long); foreach ($_keys as $_key) unset($_arr[$_key]); } $a=Array( 'a'=>'aa', 'b'=>'bb', 'c'=>'cc', 'd'=>'dd', 'e'=>'ee', 'f'=>'ff', ); my_array_splice($a, 'c', 3); print_r($a); // Output: Array ([a]=>aa [b]=>bb [f]=>ff) ?> ---- Manual Page -- http://www.php.net/manual/en/function.array-splice.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34813 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34813&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34813&report=yes

« previous php.notes (#53572) next »