What are the potential pitfalls of using array_sum() function to calculate the sum of values in PHP?

One potential pitfall of using the `array_sum()` function in PHP is that it will return 0 if the array is empty or contains non-numeric values. To solve this issue, you can check if the array is empty or contains non-numeric values before calculating the sum.

// Check if the array is empty or contains non-numeric values before calculating the sum
function safe_array_sum($arr) {
    if (empty($arr) || array_filter($arr, 'is_numeric') !== $arr) {
        return 0; // Return 0 if the array is empty or contains non-numeric values
    }
    
    return array_sum($arr); // Calculate the sum of numeric values in the array
}

// Example usage
$values = [1, 2, 3, 4];
echo safe_array_sum($values); // Output: 10

$invalid_values = [1, 'a', 3, 4];
echo safe_array_sum($invalid_values); // Output: 0