Array reorganization to ask for help

the following array wid and gid are the same, requiring Num accumulation, different operations are directly displayed, how to achieve array deduplication?

$arr = array(
                array(
                        "wid" => 1,
                        "gid" => 3,
                        "num" => 4,
                    ),
                array(
                        "wid" => 2,
                        "gid" => 1,
                        "num" => 4,
                    ),
                array(
                        "wid" => 1,
                        "gid" => 3,
                        "num" => 3,
                    ),
                array(
                        "wid" => 2,
                        "gid" => 1,
                        "num" => 4,
                    ),
                 array(
                        "wid" => 1,
                        "gid" => 1,
                        "num" => 4,
                    ),
         );

here are the effects I want

$arr = array(
                array(
                        "wid" => 1,
                        "gid" => 3,
                        "num" => 7,
                    ),
                array(
                        "wid" => 2,
                        "gid" => 1,
                        "num" => 8,
                    ),
                 array(
                        "wid" => 1,
                        "gid" => 1,
                        "num" => 4,
                    ),
         );
Jul.04,2022

I don't understand what effect you want


casually wrote one, and there are better ones to add

$temp = $data = [];
foreach($arr as $v){
    if(isset($temp[$v['wid']][$v['gid']])){
        $temp[$v['wid']][$v['gid']] += $v['num'];
    }else{
        $temp[$v['wid']][$v['gid']] = $v['num'];
    }
}
foreach($temp as $k=>$v){
    foreach($v as $key=>$val){
        $data[] = [
            'wid' => $k,
            'gid' => $key,
            'num' => $val
        ];
    }
}
var_dump($data);
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-7acb94-7c25.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-7acb94-7c25.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?