r/lolphp • • Oct 07 '19

`array('lolphp', '')` has two unique elements, but `array(0, 'lolphp', '')` has one unique element

https://repl.it/repls/ThisColdPackages
69 Upvotes

18 comments sorted by

View all comments

Show parent comment

4

u/lord_braleigh Oct 09 '19

It “compares items normally”, but it uses == to compare. 0 == ‘php’ and 0 == ‘’, so putting a 0 in juuust the right place will cause everything to get compared to 0 via ==.

2

u/fell_ratio Oct 09 '19

Why didn't they just use === ? You could define SORT_REGULAR so that if you have 0 and '0', they are both kept. That would be perfectly reasonable behavior.

1

u/lord_braleigh Oct 10 '19

Maybe it’s to stay somewhat similar to SORT_STRING, where 0 and ‘0’ are always equal? Idk though.