Re: array_unique and some questions on Zend hash internals
| From: | Stanislav Malyshev | Date: | Sun, 04 Jun 2000 14:54:22 +0000 |
| Subject: | Re: array_unique and some questions on Zend hash internals | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-20182@lists.php.net to get a copy of this message | ||
SV>> I'm implementing a function I've called array_unique that takes an array
SV>> (by reference) and removes all duplicate values (the first remains). It
SV>> seems to work, but I have a few problems/questions.
I'd make it ro return a new value. Because it's much more easy and
elegant to make such functions work on one array (just $arr =
array_unique($arr)) then to make by-reference one to work on copy - you
should create copy just for that.
SV>> One last thing, if I have an array indexed by numbers, say
SV>> array("a", "a", "b"), array_unique would change it into
SV>> array("a", 2 => "b"). Do you think it should be
SV>> array("a", "b")?
Yes, I think it should be array("a","b"). Though if you think there could
be a need for keys, you could make two versions - like sorts,
key-preserving and non-key-preserving.
--
Stanislav Malyshev stas@zend.com
+972-3-6139665