The first statement is for counting as it says count()
. This can be array values for example.
<?php
$array = array("x", "x", "x");
# Output: 3
echo count($array);
?>
The second statement is for checking if the variable $var
is true or not. You can translate this line as if $var is not true, then..
<?php
$array = array("x", "x", "x");
if(!$array) {
echo "True";
}else{
echo "Does nothing..";
}
?>
The third statement is for checking if the counting for $var
is greater than zero.
<?php
# Output: "Is not empty!"
$array = array("x", "x", "x");
if(count($array) > 0)
echo "Is not empty!";
}else{
echo "Empty..";
}
?>
And the last one is for checking if $var
is equal to zero.
<?php
# Output: "Does nothing.."
$array = array("x", "x", "x");
if($array == 0) {
echo "Is not empty!";
}else{
echo "Does nothing..";
}
?>
So basically all these four statements have different meanings. As answer to your question would if(count($arr) > 0)
be the best solution to check if the array has more then zero entries.