This question already has an answer here:
How does count(false) === 1
make any sense at all since count(null) === 0
?
count — Count all elements in an array, or something in an object. -http://php.net/manual/en/function.count.php
This makes even less sense since booleans are primitives and not arrays or countables
.
</div>
count
returns the number of elements. false
is one element (a boolean) but null
is nothing, null
is not a value.
Note that you can destroy a variable, for example an item in an array by setting it to null
:
$a = array(1,2,3);
$a[1] = null;
var_dump(isset($a[1]));
You will obtain false
because $a[1]
is no longer defined.
If you do the same with false:
$a = array(1,2,3);
$a[1] = false;
var_dump(isset($a[1]));
You will obtain true
because $a[1]
is set to the boolean false