note 34911 modified in function.array-splice by pollita

From: Date: Mon, 11 Aug 2003 20:56:50 +0000
Subject: note 34911 modified in function.array-splice by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53900@lists.php.net to get a copy of this message
[ Editor's Note: If you're not concerned with the indexes being contiguously numbered (such as for an associative array) then unset($ar[$ind]); will accomplish the same as the code below without requiring splice/splice/merge. If contiguous numbering IS a concern (such as for indexed arrays), you can still save time by using: unset($ar[$ind]); $ar = array_values($ar); ] Removing elements from arrays This works better - much quicker $ar = array("einstein", "bert", "colin", "descartes", "renoir"); $a = array_slice($ar, 0, $ind); $b = array_slice($ar, $ind + 1); $ar = array_merge($a, $b); --was-- Removing elements from arrays This works better - much quicker $ar = array("einstein", "bert", "colin", "descartes", "renoir"); $a = array_slice($ar, 0, $ind); $b = array_slice($ar, $ind + 1); $ar = array_merge($a, $b); http://www.php.net/manual/en/function.array-splice.php

« previous php.notes (#53900) next »