PHP——数组根据某一键值合并
其实要实现很简单直接foreach,再根据PHP中数组的特性就可以轻松实现。
2|0步骤
$info = [
[
"gname" => "特别关心" ,
"gid" => 1, "fid" => 2,
"nickname" => "立冬" ,
"avatar" => "http://cache.wangyangyang.vip/avatar_4.gif",
"remark" => "" ,
"desc" => "雪花一片一片的洒落在窗台上,田野间,为大地换上了新装~"
],
[
"gname" => "我的好友",
"gid" => 2,
"fid" => 3,
"nickname" => "立春",
"avatar" => "http://cache.wangyangyang.vip/avatar_3.jpg",
"remark" => "",
"desc" => "我在春天等着你的到来~"
],
[
"gname" => "朋友" ,
"gid" => 3,
"fid" => 4,
"nickname" => "立夏" ,
"avatar" => "http://cache.wangyangyang.vip/12222222222222.jpg" ,
"remark" => "" ,
"desc" => "你好啊,夏天!"
],
[
"gname" => "同学" ,
"gid" => 4,
"fid" => 5,
"nickname" => "小雨" ,
"avatar" => "http://cache.wangyangyang.vip/avatar_5.jpg" ,
"remark" => "" ,
"desc" => "人间四月芳菲尽,山寺桃花始盛开!"
],
[
"gname" =>"同学" ,
"gid" => 4,
"fid" => 6,
"nickname" => "残雪殇" ,
"avatar" => "http://cache.wangyangyang.vip/12222222222222.jpg" ,
"remark" => "小雪" ,
"desc" => "断桥残雪,三潭映月,君可知为何如此?"
]
]
合并后的数据
将数组中某一个相同的值作为键,然后生成一个新的三维数组