1

I have an array like

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

I want to change all item image value. I am using this code but not work correctly

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

Please help me to find out what’s wrong I am doing.

4
  • what I understood, you are deleting the entry after assigning. Like: $icon[2] = asset('uploads/apk-screen/'.$value);, In this line you are assigning. and unset($icon[2]); in this line you are removing the second element. Commented Nov 23, 2015 at 6:56
  • 1
    your array looks to be json. Have you used json_decode() to create $icon first? Commented Nov 23, 2015 at 6:57
  • foreach($icon as $key => $value) { $existngValue=$icon[$key] = $value['image']; $newVal=asset('uploads/apk-screen/'.$existngValue); $icon[$key]['image'] = $newVal; } also not work @DineshPatra Commented Nov 23, 2015 at 6:58
  • can you post the output of print_r($icon) completely. Commented Nov 23, 2015 at 7:00

1 Answer 1

1

Finally its work

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


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

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.