Sorry i it is duplicated, but I don't seem to find the exact scenario I need to clarify.
So my question is why this:
var = array ();
echo count (var);
prints 0.
and this:
var = array (array());
echo count (var);
prints 1?
Thanks!
Sorry i it is duplicated, but I don't seem to find the exact scenario I need to clarify.
So my question is why this:
var = array ();
echo count (var);
prints 0.
and this:
var = array (array());
echo count (var);
prints 1?
Thanks!
In the first case, you create an empty array.
$var = array();
The contents of this array may look like this:
[ ]
There is nothing here. So, count($var) is zero.
But if you create a nested array, you would have
$var = array(array());
The contents of $var would now be something like this:
[ [] ]
The inner array doesn't have anything inside it. But, the outer array has an empty array inside it. And therefore, its count is 1.
Consider an array to be a plastic box.
In the first case, you have nothing inside the box, and so the count is 0.
In the second case, however, you have an empty box inside the box. So, count is 1.