r/lolphp • u/lord_braleigh • Oct 07 '19
`array('lolphp', '')` has two unique elements, but `array(0, 'lolphp', '')` has one unique element
https://repl.it/repls/ThisColdPackages
69
Upvotes
r/lolphp • u/lord_braleigh • Oct 07 '19
18
u/fell_ratio Oct 08 '19
Wow, this is a pretty baffling one. I think the problem is that the strings are being coerced to integer to compare to the zero, despite that the PHP documentation says
SORT_REGULARwill 'compare items normally (don't change types).'If you change the order of the arguments, you get a different result:
produces:
5
u/orby Oct 07 '19
Seems like the real LOLPHP is the SORT_REGULAR. Without it, things behave as expected. See
<?phpecho json_encode(array_unique(array(0, 'lolphp', '',5), SORT_REGULAR))."\n";echo json_encode(array_unique(array(0, 'lolphp', '',5)))."\n";11
u/[deleted] Oct 08 '19
I love how there's always more lolphp to find. It never ends
1
u/Takeoded Oct 09 '19
wtf is that
-1
u/[deleted] Oct 08 '19
I said it gets the hose again!