Re: echo count(false); == 1 ?!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why? count() counts the number of objects in an array. Since we're giving it a scalar value, then it's one value. Would you expect count(array(false)) to give a zero or a false? How about count(0) versus count(1)?

You might be confusing false and null, which are not the same thing. False is a boolean number, null is an empty set. You'll note that count(null) gives a zero.

This is actually one of the cases where php is doing something logical. :)

Tim


On 11/27/2013 10:04 AM, php-general-digest-help@xxxxxxxxxxxxx wrote:
Really? 1?? I would have expected 0 or false or something other than
positive.*sigh*
$ php -a
php > echo count(false);
1



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux