Re: Array remove function?
| From: | Richard Lynch | Date: | Thu, 12 Apr 2007 02:17:43 +0000 |
| Subject: | Re: Array remove function? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252678@lists.php.net to get a copy of this message | ||
On Wed, April 11, 2007 8:44 am, Tijnema ! wrote:
> On 4/10/07, Richard Lynch <ceo@l-i-e.com> wrote:
>> http://php.net/array_flip followed up an unset, followed by
>> another
>> array_flip, I guess...
>
> What if you have an array like this:
> Array
> (
> [0] => Array
> (
> [0] => 1
> [1] => 2
> [2] => 2
> [3] => 2
> [4] => 2
> [5] => 4
> )
> [1] => 4
> [2] => 2
> [3] => 4
> )
>
> And i want to remove the 4, but i don't know 1 and 3. using array_flip
> wouldn't work because of my multi-dimensional array. But what if i'm
> using array_search? will it return 1 only? will it return 5?
>>
>> Why in the world you'd architect the array with a value when you
>> need
>> to unset by value in the first place is beyond me, though...
>
> Sometimes you end up with such arrays, where you need to have
> non-unique values first, so you store them in the value, and then you
> need to remove some of the non-unique values. But it's a
> multi-dimensional array...
All I can say is that if I have to be able to delete by value, then I
etiher build an inverse mapping array, or, if they arrays are going to
get bigger then X, I just skip the arrays, and architect it in the
database.
You can always write an inverse array -- if you have multiple keys for
one value, you just have to add another layer of array-ness in your
reverse map.
Searcing through an array for a value to be deleted is just something
I never personally do.
'Course, we didn't *have* array_search back when I formed this
opinion, and I'm a fossil/Luddite...
YMMV
--
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?