On a problem of PHP Recursive processing Statistics

json data is:

{
    "code": 0,
    "msg": "",
    "data": {
        "2": {
            "project_id": 2,
            "project_name": "V",
            "project_parent_id": 0,
            "_completed": 0,
            "_uncompleted": 2,
            "_count": 2,
            "children": [
                {
                    "project_id": 6,
                    "project_name": "",
                    "project_parent_id": 2,
                    "_completed": 0,
                    "_uncompleted": 0,
                    "_count": 0
                },
                {
                    "project_id": 10,
                    "project_name": "",
                    "project_parent_id": 2,
                    "_completed": 0,
                    "_uncompleted": 0,
                    "_count": 0,
                    "children": [
                        {
                            "project_id": 11,
                            "project_name": "",
                            "project_parent_id": 10,
                            "_completed": 0,
                            "_uncompleted": 0,
                            "_count": 0
                        }
                    ]
                }
            ]
        }
    },
    "debug": {
        "sql": "SELECT `project_id`,`project_name`,`project_parent_id` FROM  `odp_project` WHERE `project_id` = "2" OR `root` = "2" LIMIT 0,4",
        "entry": []
    }
}

the requirement is to count the _ completed,_uncompleted,_count in the lower and middle levels of the data to the upper level. Please tell me how to write this recursion.

Php
Mar.21,2021

cycle out the superior first, then use array_column to extract the three fields of the subordinate, and then array_sum to sum them, which is the data you want.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38bed-2c122.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38bed-2c122.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?