What are some potential optimizations for counting occurrences of a value in an array in PHP?

When counting occurrences of a value in an array in PHP, one potential optimization is to use the array_count_values() function, which returns an associative array where the keys are the unique values in the original array and the values are the counts of those values. This function eliminates the need for manually iterating through the array and counting occurrences.

// Sample array
$array = [1, 2, 3, 1, 2, 1];

// Count occurrences of each value in the array
$occurrences = array_count_values($array);

// Print the counts
foreach ($occurrences as $value => $count) {
    echo "Value: $value, Count: $count" . PHP_EOL;
}