Re: [PHP] Array remove function?

2007-04-17 Thread Chris

Tijnema ! wrote:

On 4/16/07, Jochem Maas <[EMAIL PROTECTED]> wrote:

Richard Lynch wrote:
> On Wed, April 11, 2007 9:00 pm, Jochem Maas wrote:
>> [PS - I've the pleasure of listening to a colleague do a manual
>> install
>> of Vista over an existing copy of XP and then get the really tricky
>> stuff
>> like the soundcard to work ... for the last week :-/]
>
> Give them an Ubuntu (or similar) CD and see if they want to just leave
> the Dark Side... :-)

yeah, but the vista story keeps getting worse.
how about:

1. '50% of applications can't use network because the router is in 
compatible with vista'


   a total WTF, apparently due to vista network 'auto-tuning' - 
can only be turned off

   via the cmdline.

2. undo/redo function in a whole stack of programs doesn't work unless 
you

run the program in 'administrator mode'

   omg.

3. openvpn doesn't work ... unless you run it in 'administrator mode'

4. when you finally give trying to run anything as anything other than 
an adminstrator
user your still confronted with that freakin' 'administrator mode' 
popup (which also

greys out the rest of the desktop) *everytime* you breath too loudly.

5. don't delete a folder if you want to get anything done today ... 
well at the least you'll

probably get a chance to grab a another cup of coffee.

6. er ... I'll keep you posted.


How off-topic is this?


Considering the rest of the conversation(s) going on right now, not much 
further OT than they are.


Are you picking on them as well?

:P

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-16 Thread Tijnema !

On 4/16/07, Jochem Maas <[EMAIL PROTECTED]> wrote:

Richard Lynch wrote:
> On Wed, April 11, 2007 9:00 pm, Jochem Maas wrote:
>> [PS - I've the pleasure of listening to a colleague do a manual
>> install
>> of Vista over an existing copy of XP and then get the really tricky
>> stuff
>> like the soundcard to work ... for the last week :-/]
>
> Give them an Ubuntu (or similar) CD and see if they want to just leave
> the Dark Side... :-)

yeah, but the vista story keeps getting worse.
how about:

1. '50% of applications can't use network because the router is in compatible 
with vista'

   a total WTF, apparently due to vista network 'auto-tuning' - can only be 
turned off
   via the cmdline.

2. undo/redo function in a whole stack of programs doesn't work unless you
run the program in 'administrator mode'

   omg.

3. openvpn doesn't work ... unless you run it in 'administrator mode'

4. when you finally give trying to run anything as anything other than an 
adminstrator
user your still confronted with that freakin' 'administrator mode' popup (which 
also
greys out the rest of the desktop) *everytime* you breath too loudly.

5. don't delete a folder if you want to get anything done today ... well at the 
least you'll
probably get a chance to grab a another cup of coffee.

6. er ... I'll keep you posted.


How off-topic is this?
Remember, this is the PHP list, not the Vista list.

Tijnema

ps. The name Microsoft is not really the right name for the company,
it should have been called Megasoft, because vista is overkill in
size.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-16 Thread Jochem Maas
Richard Lynch wrote:
> On Wed, April 11, 2007 9:00 pm, Jochem Maas wrote:
>> [PS - I've the pleasure of listening to a colleague do a manual
>> install
>> of Vista over an existing copy of XP and then get the really tricky
>> stuff
>> like the soundcard to work ... for the last week :-/]
> 
> Give them an Ubuntu (or similar) CD and see if they want to just leave
> the Dark Side... :-)

yeah, but the vista story keeps getting worse.
how about:

1. '50% of applications can't use network because the router is in compatible 
with vista'

a total WTF, apparently due to vista network 'auto-tuning' - can only 
be turned off
via the cmdline.

2. undo/redo function in a whole stack of programs doesn't work unless you
run the program in 'administrator mode'

omg.

3. openvpn doesn't work ... unless you run it in 'administrator mode'

4. when you finally give trying to run anything as anything other than an 
adminstrator
user your still confronted with that freakin' 'administrator mode' popup (which 
also
greys out the rest of the desktop) *everytime* you breath too loudly.

5. don't delete a folder if you want to get anything done today ... well at the 
least you'll
probably get a chance to grab a another cup of coffee.

6. er ... I'll keep you posted.

> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-11 Thread Richard Lynch
On Wed, April 11, 2007 9:00 pm, Jochem Maas wrote:
> [PS - I've the pleasure of listening to a colleague do a manual
> install
> of Vista over an existing copy of XP and then get the really tricky
> stuff
> like the soundcard to work ... for the last week :-/]

Give them an Ubuntu (or similar) CD and see if they want to just leave
the Dark Side... :-)

-- 
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



Re: [PHP] Array remove function?

2007-04-11 Thread Richard Lynch
On Wed, April 11, 2007 8:44 am, Tijnema ! wrote:
> On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-11 Thread Jochem Maas
Paul Novitski wrote:
> At 4/10/2007 03:09 PM, M.Sokolewicz wrote:
>> Such a function is inherently a Bad Idea (tm). array-values are not
>> unique. Array keys are. So unless you want to emulate the way
>> array_flip works (bad idea (tm)), I'd say: leave it be.
> 
> 
> Whoever owns that trademark has totally got to be the wealthiest person
> in this battered old world~

my guess: Bill Gates, stacks of money and nothing but bad ideas ;-)

[PS - I've the pleasure of listening to a colleague do a manual install
of Vista over an existing copy of XP and then get the really tricky stuff
like the soundcard to work ... for the last week :-/]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-11 Thread Tijnema !

On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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...

Tijnema


On Tue, April 10, 2007 2:52 pm, Tijnema ! wrote:
> On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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?
>>
>>
>


--
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



Re: [PHP] Array remove function?

2007-04-10 Thread Richard Lynch
On Tue, April 10, 2007 5:39 pm, Paul Novitski wrote:
> values.  If both keys and values are unique, I'd consider (if only
> briefly) maintaining two arrays, one a flipped version of the other,
> so I could look up key/value pairs using either node.

I do this all the time for small/medium arrays.

You'd want to avoid it, maybe for monster arrays...

But you rarely have unique keys + values if the arrays are all that
large anyway, in Real Life.

-- 
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



Re: [PHP] Array remove function?

2007-04-10 Thread Paul Novitski

At 4/10/2007 03:09 PM, M.Sokolewicz wrote:
Such a function is inherently a Bad Idea (tm). array-values are not 
unique. Array keys are. So unless you want to emulate the way 
array_flip works (bad idea (tm)), I'd say: leave it be.



Whoever owns that trademark has totally got to be the wealthiest 
person in this battered old world~


I guess one could argue that if the array values must be unique then 
you could use the associative array keys to hold those values; then 
you can use unset() to remove selected keys which *are* the 
values.  If both keys and values are unique, I'd consider (if only 
briefly) maintaining two arrays, one a flipped version of the other, 
so I could look up key/value pairs using either node.


If the values aren't unique and you want to remove all array elements 
with a given value, you might use array_walk().


Flipping the array back and forth just to unset individual elements 
seems extremely inefficient.  Besides, if the element values aren't 
unique, won't flipping the values & keys eliminate array elements 
that share the same value?


Regards,

Paul
__

Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-10 Thread Richard Lynch
On Tue, April 10, 2007 3:22 pm, Tijnema ! wrote:
> On 4/10/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:
>> OMG. Now that is the best idea. How simple. Guess I learned
>> something new
>> today too! :)
>>
>> > -Original Message-
>> > From: Lori Lay [mailto:[EMAIL PROTECTED]
>> >
>> > Use array_search() and unset()?
>
> Interesting, I didn't thought of that :)
>
> But should i submit a future request for such function?

Here's the thing...

I don't think there should be such a function for several reasons:

#1. The same value could be there for mulitple keys.
#2. What test is used to determine if values are "equal"?
Are '0' and 0 the same?
#3. array_search + unset is not exactly horrible
#4. One really shouldn't write code that paints one into this corner...
If one needs to track the values efficiently to remove them,
there should be an array (or other data structure) with the
value as a 'key' to do fast lookup of whatever needs to be deleted

All just imho, of course.


-- 
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



Re: [PHP] Array remove function?

2007-04-10 Thread M.Sokolewicz

Lori Lay wrote:

Tijnema ! wrote:

On 4/10/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:
OMG. Now that is the best idea. How simple. Guess I learned something 
new

today too! :)

> -Original Message-
> From: Lori Lay [mailto:[EMAIL PROTECTED]
>
> Use array_search() and unset()?


Interesting, I didn't thought of that :)

But should i submit a future request for such function?

Tijnema


Gad.  I have enough trouble keeping track of all the functions php has 
already :-)


I wouldn't use it very often, but others might...

I think I can smell a long thread starting ;-)

Lori
Such a function is inherently a Bad Idea (tm). array-values are not 
unique. Array keys are. So unless you want to emulate the way array_flip 
works (bad idea (tm)), I'd say: leave it be.


- tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-10 Thread Richard Lynch
http://php.net/array_flip followed up an unset, followed by another
array_flip, I guess...

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...

On Tue, April 10, 2007 2:52 pm, Tijnema ! wrote:
> On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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?
>>
>>
>


-- 
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



Re: [PHP] Array remove function?

2007-04-10 Thread Lori Lay

Tijnema ! wrote:

On 4/10/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:
OMG. Now that is the best idea. How simple. Guess I learned something 
new

today too! :)

> -Original Message-
> From: Lori Lay [mailto:[EMAIL PROTECTED]
>
> Use array_search() and unset()?


Interesting, I didn't thought of that :)

But should i submit a future request for such function?

Tijnema


Gad.  I have enough trouble keeping track of all the functions php has 
already :-)


I wouldn't use it very often, but others might...

I think I can smell a long thread starting ;-)

Lori

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-10 Thread Tijnema !

On 4/10/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:

OMG. Now that is the best idea. How simple. Guess I learned something new
today too! :)

> -Original Message-
> From: Lori Lay [mailto:[EMAIL PROTECTED]
>
> Use array_search() and unset()?


Interesting, I didn't thought of that :)

But should i submit a future request for such function?

Tijnema


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-10 Thread tg-php
Unset works, but if he's trying to do a search and remove in one function, 
unset is a step removed from that criteria (missing the 'search' part).

Looking at the array functions, I see some potential.

# array_remove(array(1=>2,2=>3),2,true); // array (2=>3)
// Keep all but where values = 2
$new_array = array_diff(array(1=>2, 2=>3, 3=>4), array(2));
print_r($new_array);

# array_remove(array(1=>2,2=>3),2,false); // array (1=>2)
// Keeps only where values = 2
$new_array = array_intersect(array(1=>2, 2=>3, 3=>4), array(2));
print_r($new_array);


So keeping the same syntax you had:

function array_remove($array, $remove, $remove_value = true) {

  $remove = array($remove);

  if ($remove_value) {
return array_diff($array, $remove);
  } else {
return array_intersect($array, $remove);
  }

}

Not a single function but a simpler version of your function.

-TG

= = = Original message = = =

http://php.net/unset


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



___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array remove function?

2007-04-10 Thread Daevid Vincent
OMG. Now that is the best idea. How simple. Guess I learned something new
today too! :) 

> -Original Message-
> From: Lori Lay [mailto:[EMAIL PROTECTED] 
> 
> Use array_search() and unset()?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Array remove function?

2007-04-10 Thread Lori Lay

Tijnema ! wrote:

On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> wrote:

http://php.net/unset


That works when you know the key, but will that work when you only
know the value?

Tijnema


Use array_search() and unset()?

Lori



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



RE: [PHP] Array remove function?

2007-04-10 Thread Buesching, Logan J
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:[EMAIL PROTECTED] 
Sent: Tuesday, April 10, 2007 3:53 PM
To: [EMAIL PROTECTED]
Cc: PHP
Subject: Re: [PHP] Array remove function?

On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Array remove function?

2007-04-10 Thread Daevid Vincent
While that is true, you need to know the key, 
you could do something like this, 
which I think is more efficient than your way...

foreach($array as $key => $value)
{
if ($value == $remove) 
{
unset($array[$key]);
//if you know there is only one hit, 
//then you could also:
//return;
//for more efficiency and speed.
}
}

> On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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



Re: [PHP] Array remove function?

2007-04-10 Thread Tijnema !

On 4/10/07, Richard Lynch <[EMAIL PROTECTED]> 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



Re: [PHP] Array remove function?

2007-04-10 Thread Richard Lynch
http://php.net/unset


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



[PHP] Array remove function?

2007-04-10 Thread Tijnema !

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