What are some potential pitfalls when using array_count_values in PHP?

One potential pitfall when using array_count_values in PHP is that it only works with one-dimensional arrays. If you try to use it with a multidimensional array, it will not give the desired result and may lead to unexpected behavior. To solve this issue, you can flatten the multidimensional array before using array_count_values.

// Flatten a multidimensional array before using array_count_values
function flattenArray($array) {
    $result = [];

    array_walk_recursive($array, function($value) use (&$result) {
        $result[] = $value;
    });

    return $result;
}

// Example usage
$multiArray = [[1, 2, 3], [2, 3, 4]];
$flatArray = flattenArray($multiArray);
$counts = array_count_values($flatArray);

print_r($counts);