合并数组(Laravel Collection)

时间:2016-10-25 12:55:15

标签: php arrays laravel

我需要加入分离数组,我正在使用Laravel 5.3 Collections。我有两个单独的对象。一个对象我从城市和街道地址之间的谷歌地图获得距离矩阵。结束响应如下所示:

[{"distance":"14.0 km"},{"distance":"85.6 km"},{"distance":"15.9 km"}]

我有另一个列出商店的回复。上面的距离矩阵与每个商店相关。商店响应如下所示:

{
    "0":{
        "id":3,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store One"
    },
    "4":{
        "id":6,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store Two"
    },
    "6":{
        "id":9,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store Three"
    }
}

我需要将each距离项加入每个商店,但我无法将两者结合起来。基本上我需要这个数组看起来像这样:

{
    "0":{
        "id":3,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store One",
        "distance":"14.0 km"
    },
    "4":{
        "id":6,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store Two",
        "distance":"85.6 km"
    },
    "6":{
        "id":9,
        "user_id":2,
        "brand_id":"2",
        "type":"store",
        "name":"Store Three",
        "distance":"15.9 km"
    }
}

非常感谢任何帮助或帮助。

1 个答案:

答案 0 :(得分:1)

尝试收集if (stringBuilder != null) { // no suggestion stringBuilder.Append("hello"); stringBuilder.Append("world"); stringBuilder.Append("!!!"); } method

zip()