Re: in the middle of shift and pop
| From: | David Otton | Date: | Wed, 20 Aug 2003 00:23:11 +0000 |
| Subject: | Re: in the middle of shift and pop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160106@lists.php.net to get a copy of this message | ||
On Wed, 20 Aug 2003 00:25:32 +0200, you wrote:
>is it possible to remove an element of an indexed array such as this exemple
> $A = array('a', 'b', 'c', 'd', 'e',
>'f');
>in a way that we can optain this result :
> $A = array('a', 'b', 'd', 'e', 'f');
>
>something like that perhaps ?
>array_remove($A, 2);
>
>If such a function does not exists, what would be the more efficient way to
>do so a lot of time on very big arrays ?
In the specific case, I would unset() the nth element then reindex.
unset ($A[2]);
$A = array_values ($A);
As to speed... *shrug*. Suck it and see.
In the general case (removing n elements), either a loop of unset()s or a
couple of array_slice()s to get the two halves and array_merge() to stick
them together.