What is the best way to determine the size of an array in PHP, especially when dealing with non-sequential keys like in the provided example?

When dealing with non-sequential keys in an array in PHP, the count() function may not provide accurate results as it counts only the elements with numeric keys. To determine the size of an array with non-sequential keys, you can use the sizeof() function, which counts all elements in the array regardless of their keys.

$array = ['a' => 'apple', 'b' => 'banana', 'c' => 'cherry'];
$arraySize = sizeof($array);
echo $arraySize;