0

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

Edited by bufospro: n/a

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by bufospro
0

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

Edited by nered: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.