sets
| From: | Stig Venaas | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | sets | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-18478@lists.php.net to get a copy of this message | ||
Hi
I'm writing an PHP4 application where I use sets a lot. The sets are
arrays, but I only care what values I have in them, not about indices
and ordering. I use the set operations union, intersection, subtraction
a lot. I also need to check whether something is an element, that's
easily done with array_in. I could do union with the array_merge
function sort of, but I don't want duplicate values. It would help if
had a function to remove duplicates though, but a specialised union
would help.
Would the following functions be accepted if I wrote them?
array array_union(array array1, array array2)
Creates an array that contains all values from array1 and array2 without
any duplicates provided array1 and array2 don't have dups.
array array_intersection(array array1, array array2)
Creates an array that contains all values that exists both in array1 and
array2.
array array_subtraction(array array1, array array2)
Creates an array that contains all values from array1 that is not in
array2.
The ordering will mostly be preserved, then they are also useful for
"lists".
Should they be named set_ rather than array_?
So what do you say, is this useful?
Stig
--
Stig Venaas
UNINETT