PHP array conversion

1 array merge
how to implement it? Thank you!

array(3) {
  [0] => array(7) {
    ["game_name"] => string(18) ""
    ["game_icon"] => string(32) "game_icon_wx0913c2de2ce8376a.png"
    ["id"] => int(1)
    ["gift_name"] => string(15) ""
    ["gift_details"] => string(23) "*5000  *100"
    ["need_score"] => int(30)
    ["gift_type"] => int(2)
  }
  [1] => array(7) {
    ["game_name"] => string(18) ""
    ["game_icon"] => string(32) "game_icon_wx0913c2de2ce8376a.png"
    ["id"] => int(2)
    ["gift_name"] => string(15) ""
    ["gift_details"] => string(25) "*50000  *1000"
    ["need_score"] => int(120)
    ["gift_type"] => int(2)
  }
  [2] => array(7) {
    ["game_name"] => string(18) ""
    ["game_icon"] => string(32) "game_icon_wx945daf05d01dad39.png"
    ["id"] => int(3)
    ["gift_name"] => string(12) ""
    ["gift_details"] => string(8) "*1"
    ["need_score"] => int(50)
    ["gift_type"] => int(1)
  }
}

modify to:

array(3) {
  [0] => array(7) {
    ["game_name"] => string(18) ""
    ["game_icon"] => string(32) "game_icon_wx0913c2de2ce8376a.png"
    ["gift"]=>array(2){
      [0]=>array(5){
        ["id"] => int(1)
        ["gift_name"] => string(15) ""
        ["gift_details"] => string(23) "*5000  *100"
        ["need_score"] => int(30)
        ["gift_type"] => int(2)
      }
      [1]=>array(5){
        ["id"] => int(2)
        ["gift_name"] => string(15) ""
        ["gift_details"] => string(25) "*50000  *1000"
        ["need_score"] => int(120)
        ["gift_type"] => int(2)
      }
    }
  }
  [2] => array(7) {
    ["game_name"] => string(18) ""
    ["game_icon"] => string(32) "game_icon_wx945daf05d01dad39.png"
    ["gift"]=>array(2){
      [0]=>array(){
        ["id"] => int(3)
        ["gift_name"] => string(12) ""
        ["gift_details"] => string(8) "*1"
        ["need_score"] => int(50)
        ["gift_type"] => int(1)
      }
    }
  }
}

array code, I don"t bother to write it. Give me a JSON array! Convenient installation and replacement test

[
{
"game_name": "",
"game_icon": "game_icon_wx0913c2de2ce8376a.png",
"id": 1,
"gift_name": "",
"gift_details": "*5000 *100",
"need_score": 30,
"gift_type": 2
},
{
"game_name": "",
"game_icon": "game_icon_wx0913c2de2ce8376a.png",
"id": 2,
"gift_name": "",
"gift_details": "*50000 *1000",
"need_score": 120,
"gift_type": 2
},
{
"game_name": "",
"game_icon": "game_icon_wx945daf05d01dad39.png",
"id": 3,
"gift_name": "",
"gift_details": "*1",
"need_score": 50,
"gift_type": 1
}
]
Php
Aug.09,2021

the first assumption is that both "game_name" and "game_icon" values are equal respectively

$data = json_decode(file_get_contents('array.json'), true);

$arr1 = array();
$arr2 = array();

foreach ($data as $item) {
    $arr2[]['gift'][0] = array_splice($item, 2);
    $arr1[] = $item;
}

//
$arr1_u = array_unique($arr1, SORT_REGULAR);

$data = array();
foreach ($arr1_u as $value) {
    /**
     * $value:
     * array(
     * 'game_name' => '',
     * 'game_icon' => 'game_icon_wx0913c2de2ce8376a.png',
     * )
     */
    //'game_name''game_icon'
    $keys = array_keys($arr1, $value);

    $item = array_merge($arr1[$keys[0]], $arr2[$keys[0]]);
    $length = count($keys);
    if ($length > 1) {
        for ($i = 1; $i < $length; $iPP) {
            $item['gift'][] = $arr2[$keys[$i]]['gift'];
        }
    }
    $data[] = $item;
}
var_dump($data[0], $data[1]);

the second, but 'game_name' value is equal

$data = json_decode(file_get_contents('array.json'), true);
$arr1 = array();
$arr2 = array();

foreach ($data as $item) {
    $arr2[]['gift'][0] = array_splice($item, 2);
    $arr1[] = $item;
}

//$arr2'game_name'
$arr_game_name = array_column($arr1, 'game_name');
$arr_game_name_u = array_unique($arr_game_name);

$data = array();

foreach ($arr_game_name_u as $value) {
    //'game_name'
    $keys = array_keys($arr_game_name, $value);

    $item = array_merge($arr1[$keys[0]], $arr2[$keys[0]]);
    $length = count($keys);
    if ($length > 1) {
        for ($i = 1; $i < $length; $iPP) {
            $item['gift'][] = $arr2[$keys[$i]]['gift'][0];
        }
    }
    $data[] = $item;
}

array code, I don't bother to write it. Give me a JSON array! Convenient installation and replacement test

[
{
"game_name": "",
"game_icon": "game_icon_wx0913c2de2ce8376a.png",
"id": 1,
"gift_name": "",
"gift_details": "*5000 *100",
"need_score": 30,
"gift_type": 2
},
{
"game_name": "",
"game_icon": "game_icon_wx0913c2de2ce8376a.png",
"id": 2,
"gift_name": "",
"gift_details": "*50000 *1000",
"need_score": 120,
"gift_type": 2
},
{
"game_name": "",
"game_icon": "game_icon_wx945daf05d01dad39.png",
"id": 3,
"gift_name": "",
"gift_details": "*1",
"need_score": 50,
"gift_type": 1
}
]
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-1eafbde-48051.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-1eafbde-48051.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?