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 for 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;
    }
}

Thanks a lot both

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.