Re: Removing items from an Array

2012-02-20 Thread James Miller
On 18 February 2012 05:30, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, February 17, 2012 14:44:42 Mars wrote: On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the

Removing items from an Array

2012-02-17 Thread Mars
Hello everybody. Once again I have a little question, this time about removing items from an assoc array in a foreach. Why does the following code: http://pastebin.com/65P9WDNS Result in this output: http://pastebin.com/4FzEE1zi It seems rather strange to me. I'd expect the foreach_reverse

Re: Removing items from an Array

2012-02-17 Thread Jonathan M Davis
On Friday, February 17, 2012 11:00:36 Mars wrote: Hello everybody. Once again I have a little question, this time about removing items from an assoc array in a foreach. Why does the following code: http://pastebin.com/65P9WDNS Result in this output: http://pastebin.com/4FzEE1zi

Re: Removing items from an Array

2012-02-17 Thread Mars
On Friday, 17 February 2012 at 10:13:00 UTC, Jonathan M Davis wrote: I don't believe that removing elements from an AA while iterating over it is safe. - Jonathan M Davis Well, no. But from my experience it's okay from bottom to top... at least in other languages. What would be the

Re: Removing items from an Array

2012-02-17 Thread Andrej Mitrovic
foreach_reverse isn't going to help you much since AA's do not save the order of the keys. A quick workaround: http://pastebin.com/KkECqwUU Others probably know efficient ways to do this.

Re: Removing items from an Array

2012-02-17 Thread Andrea Fontana
Usually in other languages iterators are safe. Il giorno ven, 17/02/2012 alle 11.35 +0100, Mars ha scritto: On Friday, 17 February 2012 at 10:13:00 UTC, Jonathan M Davis wrote: I don't believe that removing elements from an AA while iterating over it is safe. - Jonathan M Davis

Re: Removing items from an Array

2012-02-17 Thread James Miller
AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array as you loop through it. -- James Miller

Re: Removing items from an Array

2012-02-17 Thread Mars
On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array as you loop through it. -- James Miller Too bad. So,

Re: Removing items from an Array

2012-02-17 Thread Jonathan M Davis
On Friday, February 17, 2012 14:44:42 Mars wrote: On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array

Re: Removing items from an Array

2012-02-17 Thread Steven Schveighoffer
On Fri, 17 Feb 2012 08:44:42 -0500, Mars -@-.- wrote: On Friday, 17 February 2012 at 13:33:25 UTC, James Miller wrote: AAs don't keep the key order, so when you delete something out of it, what ever system iterates to the next pointer gets confused. Its generally a bad idea to modify an array