How does the count() function work in PHP and what types of parameters does it expect?

The count() function in PHP is used to count the number of elements in an array or the number of properties in an object. It can also be used to count elements in other types of data structures. The function expects an array or an object as its parameter, and it returns the number of elements or properties found.

// Example of using the count() function with an array
$fruits = array("apple", "banana", "orange");
echo count($fruits); // Outputs: 3

// Example of using the count() function with an object
$person = new stdClass();
$person->name = "John";
$person->age = 30;
echo count((array)$person); // Outputs: 2