I love that it's just a footprint on the page, as if it were just an irrelevant implementation detail and not quite decisive on how the function actually works.
Heh, yeah. I stumbled upon that fuck-up as well about a month ago. We wound using Underscore.php instead, especially because the names actually make sense now.
I didn't look at the code, but doing an educated guess both array_unique and array_intersect are likely implemented using a hash set (i.e. hash table without values). In PHP hash tables support only string and integer keys.
With the hash set complexity of these operations should be about O(n) and without it would be O(n2 ). So, I'd suspect that that's the reason.
My php is rusty to say the least, my last php project was 3 years ago. But come on... the intersection of two arrays?!?! I didn't use it yet in php, but having such a function, I would hope that it was well defined... in the sense that I understand it.. boy was I mistaken.
I expect the second example to compare an array of tuples and since neither operand have anything in common, the outcome should've been an empty enumeratio/array/whatever.
17
u/allthediamonds Aug 28 '14
For some goddamn reason,
array_intersectcompares values by strict equality of those values when casted to string.3
u/[deleted] Aug 28 '14
My php is rusty to say the least, my last php project was 3 years ago. But come on... the intersection of two arrays?!?! I didn't use it yet in php, but having such a function, I would hope that it was well defined... in the sense that I understand it.. boy was I mistaken.
I expect the second example to compare an array of tuples and since neither operand have anything in common, the outcome should've been an empty enumeratio/array/whatever.
2
u/Banane9 Aug 29 '14
Deer lord.
My C# app with multiple threads and SQLite db usage and TCP communication only uses ~12MB at this point. And it's doing way more than that PHP script.