Php merge array

I want to change the array above into something like the following. A good way.
public function arr_uniqe ($arr,$key)

{
    $key_arr = [];
    $color = [];
    foreach ($arr as $k => $v) {
        if(empty($color)){
            $color[] = $v["color"];
            $key_arr[$v["color"]]["id"] = $v["id"];
            $key_arr[$v["color"]]["name"] = $v["name"];
            $key_arr[$v["color"]]["cate_id"] = $v["cate_id"];
            $key_arr[$v["color"]]["color"] = $v["color"];
            $key_arr[$v["color"]]["color_imgurl"] = $v["color_imgurl"];
            $key_arr[$v["color"]]["gouzao"]["gouzao_".$v["gouzao"]] = $v["gouzao"];
            $key_arr[$v["color"]]["gouzao"]["gouzao_imgurl_".$v["gouzao"]] = $v["gouzao_imgurl"];
        }else{
            if(in_array($v["color"],$color)){
                  $key_arr[$v["color"]]["gouzao"]["gouzao_".$v["gouzao"]] = $v["gouzao"];
                  $key_arr[$v["color"]]["gouzao"]["gouzao_imgurl_".$v["gouzao"]] = $v["gouzao_imgurl"];
            }else{
                    $color[] = $v["color"];
                    $key_arr[$v["color"]]["id"] = $v["id"];
                    $key_arr[$v["color"]]["name"] = $v["name"];
                    $key_arr[$v["color"]]["cate_id"] = $v["cate_id"];
                    $key_arr[$v["color"]]["color"] = $v["color"];
                    $key_arr[$v["color"]]["color_imgurl"] = $v["color_imgurl"];
                    $key_arr[$v["color"]]["gouzao"]["gouzao_".$v["color"]] = $v["gouzao"];
                    $key_arr[$v["color"]]["gouzao"]["gouzao_imgurl_".$v["color"]] = $v["gouzao_imgurl"];
            }
        }
       
    }
    //sort($arr);
    return $key_arr;
}
Php
Dec.24,2021

if it exists, it updates the gouzao, and creates a new

if it doesn't exist.
if (!isset($key_arr[$v['color']])) {
    $key_arr[$v['color']]= [];
    $key_arr[$v['color']]['id'] = $v['id'];
    $key_arr[$v['color']]['name'] = $v['name'];
    $key_arr[$v['color']]['cate_id'] = $v['cate_id'];
    $key_arr[$v['color']]['color'] = $v['color'];
    $key_arr[$v['color']]['color_imgurl'] = $v['color_imgurl'];
}

$key_arr[$v['color']]['gouzao']['gouzao_'.$v['gouzao']] = $v['gouzao'];
$key_arr[$v['color']]['gouzao']['gouzao_imgurl_'.$v['gouzao']] = $v['gouzao_imgurl'];
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-1ea023d-1aac.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-1ea023d-1aac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?