implementing set theory operations in php
Asked Answered
D

2

6

How to implement set theory operations in pure php?

Demimonde answered 17/8, 2010 at 2:3 Comment(0)
I
10

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?

Isomagnetic answered 17/8, 2010 at 2:26 Comment(1)
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
S
2

Probably you'll already saw those links:

http://jamietalbot.com/2010/02/04/set-operations-in-php/

http://oreilly.com/catalog/progphp/chapter/ch05.html

Saiva answered 17/8, 2010 at 2:27 Comment(3)
For comparing non-scalar values, such as stdClass objects and other data types.Mawson
web.archive.org/web/20201021103045/http://jamietalbot.com/2010/…Palaeography
web.archive.org/web/20080905054045/http://oreilly.com/catalog/…Palaeography

© 2022 - 2024 — McMap. All rights reserved.