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

From: Date: Wed, 27 Nov 2013 18:25:52 +0000
Subject: Re: echo count(false); == 1 ?!
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-322518@lists.php.net to get a copy of this message
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@lists.php.net wrote:
Really? 1?? I would have expected 0 or false or something other than positive.*sigh* $ php -a php > echo count(false); 1


« previous php.general (#322518) next »