PHP count() Function Explained
In PHP, the purpose of the count() function is to get the number of elements in an array or object. It can be used to calculate the length of an array or the number of properties in an object. The count() function can take an array or a countable object as a parameter and return the number of elements in that object. If the parameter is not an array or countable object, it returns 0.
例子:= Example:
$numbers = [1, 2, 3, 4, 5];
$count = count($numbers);
echo $count; // 输出: 5
$person = new stdClass();
$person->name = 'John';
$person->age = 25;
$count = count($person);
echo $count; // 输出: 2
$emptyArray = [];
$count = count($emptyArray);
echo $count; // 输出: 0