Esempio n. 1
0
function array_sum_recursive($array)
{
    $sum = 0;
    foreach ($array as $value) {
        if (is_array($value)) {
            $sum += array_sum_recursive($value);
        } elseif (is_int($value)) {
            $sum += $value;
        }
    }
    return $sum;
}
Esempio n. 2
0
function array_sum_recursive($array)
{
    if (is_object($array) && false !== array_search('red', (array) $array, true)) {
        return 0;
    }
    $sum = 0;
    foreach ((array) $array as $value) {
        if (is_object($value) || is_array($value)) {
            $sum += array_sum_recursive($value);
        } elseif (is_int($value)) {
            $sum += $value;
        }
    }
    return $sum;
}