What are common pitfalls when using the count() function in PHP?

One common pitfall when using the count() function in PHP is not checking if the variable being counted is an array or an object. If the variable is not an array or an object, count() will return 1, which may lead to unexpected results. To avoid this issue, always ensure that the variable is of the correct type before using count().

// Check if the variable is an array before using count()
if(is_array($array)){
    $count = count($array);
} else {
    $count = 0;
}