Elegant way to aggregate multi-demensional array by index key

Posted by Stephen J. Fuhry on Stack Overflow See other posts from Stack Overflow or by Stephen J. Fuhry
Published on 2010-05-05T19:04:14Z Indexed on 2010/05/05 19:08 UTC
Read the original article Hit count: 136

How can I recursively find the total value of all children of an array that looks something like this?

 [0] => Array
    (
        [value] => ? // 8590.25 + 200.5 + 22.4
        [children] => Array
            (
                [0] => Array
                    (
                        [value] => ? // 8590.25 + 200.5
                        [children] => Array
                            (
                                [0] => Array
                                    (
                                        [value] => 8590.25 // leaf node
                                    )
                                [1] => Array
                                    (
                                        [value] => 200.05 // leaf node
                                    )
                            )

                    )
                [1] => Array
                    (
                        [value] => 22.4 // leaf node
                    )
             )
    )

© Stack Overflow or respective owner

Related posts about php

Related posts about recursion