What are the advantages of using array_count_values() function in PHP for counting occurrences of symbols in a slot machine game with multiple reels?

When developing a slot machine game with multiple reels, one common task is to count the occurrences of symbols on each reel. This information is crucial for determining the outcome of the game and calculating payouts. Using the array_count_values() function in PHP can simplify this task by efficiently counting the occurrences of each symbol in an array, making it easier to track and analyze the results.

// Sample array representing symbols on a reel
$reel = ['cherry', 'bell', 'cherry', 'bar', 'cherry'];

// Count the occurrences of each symbol
$occurrences = array_count_values($reel);

// Output the results
foreach ($occurrences as $symbol => $count) {
    echo "Symbol: $symbol, Count: $count" . PHP_EOL;
}