note 34813 deleted from function.array-splice by tomsommer

From: Date: Fri, 16 Jul 2004 17:30:43 +0000
Subject: note 34813 deleted from function.array-splice by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73404@lists.php.net to get a copy of this message
Note Submitter: plyrvt at mail dot ru (Yura Pylypenko) ---- 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) ?>

« previous php.notes (#73404) next »