note 34911 modified in function.array-splice by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:49:47 +0000 |
| Subject: | note 34911 modified in function.array-splice by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79934@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
<?php
$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--
[ 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);
http://php.net/manual/en/function.array-splice.php