Multi level object data manipulation PHP : I have a multi-level object data with a structure similar to the window below. 

I am trying to

* sum all the direct package values for the top users or say `parents`, only
* sum all the nested indirect package values from the `children` tree.

The final result is expected to be similar to:
`[{"sum_direct": 600},{"sum_indirect": 3000}]`


<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

    {
      "users": [{
          "user_id": 2,
          "ref_id": 1,
          "package": [{
              "name": "Basic"
            },
            {
              "direct": 200
            },
            {
              "indirect": 100
            }
          ],
          "children": [{
              "user_id": 58,
              "ref_id": 2,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 59,
              "ref_id": 2,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 111,
              "ref_id": 2,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 116,
              "ref_id": 2,
              "package": [{
                  "name": "Diamond"
                },
                {
                  "direct": 1000
                },
                {
                  "indirect": 500
                }
              ],
              "children": 0
            },
            {
              "user_id": 119,
              "ref_id": 2,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            }
          ]
        },
        { ...
        },
        {
          "user_id": 100,
          "ref_id": 1,
          "package": [{
              "name": "Basic"
            },
            {
              "direct": 200
            },
            {
              "indirect": 100
            }
          ],
          "children": [{
              "user_id": 101,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 102,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 103,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 104,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 105,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 106,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 107,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 108,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 109,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 110,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            },
            {
              "user_id": 117,
              "ref_id": 100,
              "package": [{
                  "name": "Diamond"
                },
                {
                  "direct": 1000
                },
                {
                  "indirect": 500
                }
              ],
              "children": 0
            },
            {
              "user_id": 129,
              "ref_id": 100,
              "package": [{
                  "name": "Diamond"
                },
                {
                  "direct": 1000
                },
                {
                  "indirect": 500
                }
              ],
              "children": 0
            },
            {
              "user_id": 130,
              "ref_id": 100,
              "package": [{
                  "name": "Basic"
                },
                {
                  "direct": 200
                },
                {
                  "indirect": 100
                }
              ],
              "children": 0
            }
          ]
        }
      ]
    }

<!-- end snippet -->


Complete data at [users.json][1]

  [1]: https://github.com/bishoplee/mlu/edit/master/users.json