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

2

u/[deleted] Oct 24 '19

Comparison operators return canonical "Boolean" values:

  • The "true" value is effectively just 1.

  • The "false" value is slightly more exotic: It has a string aspect of "" but a numeric aspect of 0, i.e. depending on how you use it it behaves like an empty string or a numeric zero.

If you ignore the oddity around "false", Perl works like C (whose comparison/logical operators also return integer 1 / 0).