Re: SV: SV: [PHP4BETA] unset() bug or feature?
| From: | Zeev Suraski | Date: | Mon, 03 Jan 2000 21:40:29 +0000 |
| Subject: | Re: SV: SV: [PHP4BETA] unset() bug or feature? | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-8870@lists.php.net to get a copy of this message | ||
At 19:12 03/01/2000 , Johan Ekenberg wrote:
Ah no. There are really two internal pointers (of different kinds) inside a hash. One is a real pointer, that points to the current entry in the hash (the one that would be returned by the next call to each()). The other is basically just an incrementing number, that is used to give automatic indices to array elements that were inserted with implicit keys (i.e. $foo[] = $bar). This number never decreases.Yes. But look at this: $array[0] = "Set";now contains 0 items.print count($array); // prints: 1 unset ($array[0]); // $arrayIt doesn't help what? As far as I understand it doesn't reset the internal array pointer to $array[0]. If it would, the subsequent addition to $array[] would be placed in $array[0] and not $array[1] as is the case.reset($array); // This doesn't help
I missed your earlier posts I guess, but that's the intended behavior. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/$array (which contains _zero_ items!)print count($array); // prints: 0 $array[] = "Set"; // Add toall items areprint count($array); // prints: 1 print "$array[0]"; // prints: (nothing) print "$array[1]"; // prints: SetQuestions: 1. Why isn't the internal array pointer reset when any orunset()?Why should it? It should only move if the element being unset is the one currently pointed by the internal pointer, and then too it shouldn't reset, but move to the next element. Ok, I won't argue more on that.2. Why doesn't reset() reset the internal array pointer?It does. What makes you think it doesn't? See comment above. $array[] = "Set" adds to $array[1] even though $array was just reset(). Shouldn't it add to $array[0] ??