RE: [PHP] Array remove function?
| From: | Buesching, Logan J | Date: | Tue, 10 Apr 2007 20:00:54 +0000 |
| Subject: | RE: [PHP] Array remove function? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252457@lists.php.net to get a copy of this message | ||
Something along these lines?
$flipped=array_flip($arr);
unset($flipped[$val])
return array_flip($flipped);
From the manual of array_flip:
If a value has several occurrences, the latest key will be used as its
values, and all others will be lost.
-Logan
-----Original Message-----
From: Tijnema ! [mailto:tijnema@gmail.com]
Sent: Tuesday, April 10, 2007 3:53 PM
To: ceo@l-i-e.com
Cc: PHP
Subject: Re: [PHP] Array remove function?
On 4/10/07, Richard Lynch <ceo@l-i-e.com> wrote:
> http://php.net/unset
That works when you know the key, but will that work when you only
know the value?
Tijnema
>
>
> On Tue, April 10, 2007 2:49 pm, Tijnema ! wrote:
> > Hi,
> >
> > Is there currently a function that removes a key/value from an
array?
> > I use this code right now:
> > function array_remove($array,$remove,$remove_value = true)
> > {
> > foreach($array as $key => $value) {
> > if($remove_value && $value != $remove) {
> > $new_array[$key] = $value;
> > } elseif (!$remove_value && $key != $remove) {
> > $new_array[$key] = $value;
> > }
> > }
> > return $new_array;
> > }
> >
> > array_remove(array(1=>2,2=>3),2,true); // array (2=>3)
> > array_remove(array(1=>2,2=>3),2,false); // array (1=>2)
> >
> > Anyone knows if there already exists such function?
> >
> > Else should i create future request?
> >
> > Tijnema
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php