PHP 数组转换

1数组合并
请问下怎么实现呢?谢谢了!

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)
  }
}

修改为 :

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)
      }
    }
  }
}

数组代码,我也懒得写了。给个JSON 数组吧!方便装换测试

[
{
"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
}
]
HUX布斯
浏览 438回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP