Hi,
I have a php array as the following format
array([4]=>6 [8]=>12 [3]=>5)
and I would like to add 6+12+5

The problem I have is that neither number of array cells nor array_keys are known.

Thanks a lot

Member Avatar

diafol

$total = array_sum($myarray);
commented: asap method :) - Zero13 +6

EDIT: I miss read your question.. sorry


You could do a while or for loop and just print it all out.
Or use a foreach.

public function iterateNestedArray($array) {
    if (is_array($array)) {
        foreach ($array as $key => $value) {
            print_r(iterateNestedArray($value));
        }
    }
    else {
        return $array;
    }
}