RE: [PHP] removing an element from an array
| From: | Daniel Perez Clavero | Date: | Wed, 01 Oct 2003 11:08:49 +0000 |
| Subject: | RE: [PHP] removing an element from an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-164533@lists.php.net to get a copy of this message | ||
Copy/Paste to a php file, and observe how it works. Maybe could be usefull
for u
<?
$array1[0]="Red";
$array1[1]="Blue";
$array1[2]="White";
$array1[3]="Black";
$array2[0]="Blue";
$array2[1]="Black";
$array1_result_diff=array_diff($array1, $array2);
echo "This is an array with colors not starting with <B>\"B\"</B>";
echo "<BR>";
echo var_dump($array1_result_diff);
echo "<BR>";
echo "<BR>";
echo "<BR>";
$array2_result_diff=array_intersect($array1, $array2);
echo "This is an array with colors starting with <B>\"B\"</B>";
echo "<BR>";
echo var_dump($array2_result_diff);
?>
-----Original Message-----
From: Angelo Zanetti [mailto:binc2@ctech.ac.za]
Sent: miércoles, 01 de octubre de 2003 12:25
To: Php-General@Lists.Php.Net
Subject: [PHP] removing an element from an array
Hi
If I have an array and want to remove and element from this array. correct
me if this is the wrong approach:
create a temporary array with 1 element less than the origional array, get
the position of the element ( is there a function for this?) and then run
through the origional array copying all elements besides the element which
is meant to be removed.
Is there no function to do this? It seems like alot of overhead to do this
process, especially if the array is big. comments?
Angelo
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php