Re: [PHP-DEV] removing an item from an array

2012-08-22 Thread Yasuo Ohgaki
Hi, 2012/8/22 Andrew Faulds : > Um, Yasuo, have you looked at array_walk implementation and ascertained it > is safe to change array structure while using it? > > Because I'm worried you're changing docs without doing so. Simply deleting current element is safe. It's done in everywhere in PHP. It

Re: [PHP-DEV] removing an item from an array

2012-08-21 Thread Andrew Faulds
Um, Yasuo, have you looked at array_walk implementation and ascertained it is safe to change array structure while using it? Because I'm worried you're changing docs without doing so. -- Sent from Samsung Mobile Andrew Faulds http://ajf.me/ Yasuo Ohgaki wrote: Hi, 2012/8/22 Levi Morrison : >

Re: [PHP-DEV] removing an item from an array

2012-08-21 Thread Yasuo Ohgaki
Hi, 2012/8/22 Levi Morrison : > On Tue, Aug 21, 2012 at 7:45 PM, Yasuo Ohgaki wrote: >> >> Hi, >> >> 2012/8/16 Rasmus Schultz : >> > How come there is no straight-foward obvious way to simply remove a given >> > value from an array? >> > >> > Just look at the number of horrible ways people solve

Re: [PHP-DEV] removing an item from an array

2012-08-21 Thread Levi Morrison
On Tue, Aug 21, 2012 at 7:45 PM, Yasuo Ohgaki wrote: > > Hi, > > 2012/8/16 Rasmus Schultz : > > How come there is no straight-foward obvious way to simply remove a given > > value from an array? > > > > Just look at the number of horrible ways people solve this obvious problem: > > > > http://stac

Re: [PHP-DEV] removing an item from an array

2012-08-21 Thread Yasuo Ohgaki
Hi, 2012/8/16 Rasmus Schultz : > How come there is no straight-foward obvious way to simply remove a given > value from an array? > > Just look at the number of horrible ways people solve this obvious problem: > > http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key > > Sho

Re: [PHP-DEV] removing an item from an array

2012-08-20 Thread Rasmus Schultz
I think adding more collection-types is the intuitive reaction to this issue, but there's something to be said for the idea of having only a single collection-type - I think that's one PHP feature we should not give up. Not having to pick and choose (and compromise) to select the "right" collectio

Re: [PHP-DEV] removing an item from an array

2012-08-19 Thread Lars Schultz
Sorry for creating more "noise"... Am 18.08.2012 06:59, schrieb Sherif Ramadan: Further more, your assumption here that the result is incorrect (or improperly indexed) is completely baseless and moot. You are making a bold assumption that I both care about the keys and that I expect them to be n

Re: Re: [PHP-DEV] removing an item from an array

2012-08-18 Thread Morgan L. Owens
On 2012-08-19 04:08, Levi Morrison wrote: On Sat, Aug 18, 2012 at 12:42 AM, Alexey Zakhlestin wrote: On 16.08.2012, at 0:18, Rasmus Schultz wrote: How come there is no straight-foward obvious way to simply remove a given value from an array? Well, this sounds like a reason for creating Sp

Re: [PHP-DEV] removing an item from an array

2012-08-18 Thread Levi Morrison
On Sat, Aug 18, 2012 at 12:42 AM, Alexey Zakhlestin wrote: > > On 16.08.2012, at 0:18, Rasmus Schultz wrote: > >> How come there is no straight-foward obvious way to simply remove a given >> value from an array? > > Well, this sounds like a reason for creating SplSet class > There's already SplO

Re: [PHP-DEV] removing an item from an array

2012-08-17 Thread Alexey Zakhlestin
On 16.08.2012, at 0:18, Rasmus Schultz wrote: > How come there is no straight-foward obvious way to simply remove a given > value from an array? Well, this sounds like a reason for creating SplSet class -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www

Re: [PHP-DEV] removing an item from an array

2012-08-17 Thread Sherif Ramadan
On Thu, Aug 16, 2012 at 2:39 AM, Lars Schultz wrote: > Am 16.08.2012 07:55, schrieb Sherif Ramadan: > >> Now your array is something completely different from what you wanted. >> The solution stated earlier is the most sane one (just using >> array_keys() with a search value). > > > the array_keys

Re: [PHP-DEV] removing an item from an array

2012-08-16 Thread Lester Caine
Sherif Ramadan wrote: I don't wish to degrade anyone's contributions to this thread, but this really is the perfect example of making a lot of fuss over nothing on the mailing list and an example of the kinds of discussion we should be avoiding when there are so many other important problems we c

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Morgan L. Owens
On 2012-08-16 17:55, Sherif Ramadan wrote: > That doesn't make any sense. What if the values are present more than > once? array_flip will cause the keys to be overwritten. > Not to mention converting all of the array's elements to strings and/or integers. Now your array is something complete

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Lars Schultz
Am 16.08.2012 07:55, schrieb Sherif Ramadan: Now your array is something completely different from what you wanted. The solution stated earlier is the most sane one (just using array_keys() with a search value). the array_keys solution is slower (although barely) than my suggested array_slice

Re: Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Sherif Ramadan
> > This is my favourite way of removing a value: > $kv = array( 1 => 'a', 2 => 'b', 3 => 'c'); > $vk = array_flip($kv); > unset($vk['b']); > $kv = array_flip($vk); That doesn't make any sense. What if the values are present more than once? array_flip will cause the keys to be overwritten. $arra

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Lars Schultz
Am 15.08.2012 22:22, schrieb Stas Malyshev: Just look at the number of horrible ways people solve this obvious problem: I see: if(($key = array_search($del_val, $messages)) !== false) { unset($messages[$key]); } Nothing horrible here. One thing that should be noted in this case and any s

Re: Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Tyler L
On Wed, Aug 15, 2012 at 7:59 PM, Morgan L. Owens wrote: > On 2012-08-16 08:27, Nikita Popov wrote: > >> On Wed, Aug 15, 2012 at 10:22 PM, Stas Malyshev >> wrote: >> >>> Hi! >>> >>> How come there is no straight-foward obvious way to simply remove a given value from an array? Just

Re: Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Morgan L. Owens
On 2012-08-16 08:27, Nikita Popov wrote: On Wed, Aug 15, 2012 at 10:22 PM, Stas Malyshev wrote: Hi! How come there is no straight-foward obvious way to simply remove a given value from an array? Just look at the number of horrible ways people solve this obvious problem: I see: if(($key = ar

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Kris Craig
On Wed, Aug 15, 2012 at 1:35 PM, Kris Craig wrote: > > > On Wed, Aug 15, 2012 at 1:31 PM, Nikita Popov wrote: > >> On Wed, Aug 15, 2012 at 10:29 PM, Kris Craig >> wrote: >> >> >> >> Btw, deleting all values (not just the first) is also very easy >> currently: >> >> >> >> foreach (array_keys($arr

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Kris Craig
On Wed, Aug 15, 2012 at 1:31 PM, Nikita Popov wrote: > On Wed, Aug 15, 2012 at 10:29 PM, Kris Craig wrote: > >> > >> Btw, deleting all values (not just the first) is also very easy > currently: > >> > >> foreach (array_keys($array, $delValue) as $key) { > >> unset($array[$key]); > >> } > >>

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Nikita Popov
On Wed, Aug 15, 2012 at 10:29 PM, Kris Craig wrote: >> >> Btw, deleting all values (not just the first) is also very easy currently: >> >> foreach (array_keys($array, $delValue) as $key) { >> unset($array[$key]); >> } >> > > Even easier still, just do this: > > $array_var = array(); It's ofte

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Kris Craig
> > > Btw, deleting all values (not just the first) is also very easy currently: > > foreach (array_keys($array, $delValue) as $key) { > unset($array[$key]); > } > > Even easier still, just do this: $array_var = array(); --Kris

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Nikita Popov
On Wed, Aug 15, 2012 at 10:22 PM, Stas Malyshev wrote: > Hi! > >> How come there is no straight-foward obvious way to simply remove a given >> value from an array? > > The same reason there's no simple way to undefine variable whose value > is 42 without knowing the variable name. Array is a conta

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Will Fitch
I like that chose 42 for the value. You win, and I completely agree. On Wed, Aug 15, 2012 at 4:22 PM, Stas Malyshev wrote: > Hi! > > > How come there is no straight-foward obvious way to simply remove a given > > value from an array? > > The same reason there's no simple way to undefine variable

Re: [PHP-DEV] removing an item from an array

2012-08-15 Thread Stas Malyshev
Hi! > How come there is no straight-foward obvious way to simply remove a given > value from an array? The same reason there's no simple way to undefine variable whose value is 42 without knowing the variable name. Array is a container indexed by keys, not values. So if you've got just a value, t

[PHP-DEV] removing an item from an array

2012-08-15 Thread Rasmus Schultz
How come there is no straight-foward obvious way to simply remove a given value from an array? Just look at the number of horrible ways people solve this obvious problem: http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key Shouldn't we have something simple, like: a