Re: in the middle of shift and pop
| From: | Decapode Azur | Date: | Tue, 19 Aug 2003 23:31:16 +0000 |
| Subject: | Re: in the middle of shift and pop | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-160097@lists.php.net to get a copy of this message | ||
> 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 ?
perhaps this way :
<?php
function array_remove($array, $remove) {
foreach ($remove as $rem) unset($array[$rem]);
foreach($array as $a) $rem_array[] = $a;
return $rem_array;
}
$array =
array('A','B','C','D','E','F','G','H','I','J');
$remove = array(2, 5, 7);
print_r($array);
$rem_array = array_remove($array, $remove);
print_r($rem_array);
?>