How to implement set theory operations in pure php?
implementing set theory operations in php
Asked Answered
Which operations are you looking for? What are you trying to accomplish?
In PHP an array is (imperfectly) analogous to a set, and PHP has array_intersect
, array_merge
(union), and array_diff
(complement) functions built in. There's also array_uintersect
and array_udiff
for handling complex objects whose comparisons are not so straightforward.
Is there further functionality you need?
It's worth noting that array_merge isn't a true union according to set theory. You have to do array_merge then array_unique on the result otherwise you can end up with duplicates. The link that Strae provided in his answer to Programming PHP demonstrates this. –
Biography
Probably you'll already saw those links:
For comparing non-scalar values, such as stdClass objects and other data types. –
Mawson
© 2022 - 2024 — McMap. All rights reserved.