What is the best approach to summing up values in a multidimensional array in PHP?

To sum up values in a multidimensional array in PHP, you can use a recursive function that iterates through each element of the array and adds up the values. This approach allows you to handle arrays of any depth and size.

function sumMultiArray($arr) {
    $sum = 0;
    foreach ($arr as $value) {
        if (is_array($value)) {
            $sum += sumMultiArray($value);
        } else {
            $sum += $value;
        }
    }
    return $sum;
}

$multiArray = [[1, 2], [3, [4, 5]]];
$totalSum = sumMultiArray($multiArray);
echo $totalSum; // Output: 15