使用foreach循环更改数组键值


Change array key value with foreach loop

我有一个类似的数组

  "id": "948",
  "app_id": "172",
  "image": "75733F51448032347-img.png",
  "type": "phone",
  "created_at": "2015-11-21 02:12:27",
  "updated_at": "2015-11-21 02:12:27"
},
{
  "id": "950",
  "app_id": "172",
  "image": "5813pKb1448032353-img.png",
  "type": "phone",
  "created_at": "2015-11-21 02:12:33",
  "updated_at": "2015-11-21 02:12:33"
},
{
  "id": "951",
  "app_id": "172",
  "image": "6864qUU1448032355-img.png",
  "type": "phone",
  "created_at": "2015-11-21 02:12:35",
  "updated_at": "2015-11-21 02:12:35"
}

我想更改所有项目的图像值。我正在使用此代码,但不能正常工作

foreach($icon as $key => $value)
{
    $icon[2] = asset('uploads/apk-screen/'.$value);
    unset($icon[2]);
}

请帮我找出我做错了什么。

最后它的工作

   foreach($icon as $key => $value)
    {
        $existngValue=$icon[$key]['image'] = $value['image'];

        $newVal=asset('uploads/apk-screen/'.$existngValue);
        $icon[$key]['image'] = $newVal;
    }