Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:09:29+00:00 2026-06-13T12:09:29+00:00

Passing values to an array via foreach loop then in first array result was

  • 0

Passing values to an array via foreach loop then in first array result was ok but in the second,third and so forth it repeats the values of before array like in the array second it repeats the value of array first, in the third array it repeats the array values of the second. How can I fix this?

Here’s how I pass my values to my array:

   <?php

//
$item_holder = array();
$item_feature_holder = array();
$item_shipping_holder = array();
$item_imagesets_holder = array();

    //Get items from amazon
    foreach($response->Items->Item as $item){
        //Display item features
        if(isset($item->ItemAttributes->Feature)){
            if(is_array($item->ItemAttributes->Feature)){
                foreach($item->ItemAttributes->Feature as $itemFeature){
                    echo '<p>'.$itemFeature.'</p>';
                    $item_feature_holder[] = $itemFeature;
                }
            }
            else{
                echo '<p>'.$item->ItemAttributes->Feature.'</p>';
            }
        }

        //Display more images
        foreach($item->ImageSets->ImageSet as $moreImage){
            if(isset($moreImage->ThumbnailImage)){
                $item_imagesets_holder[] = $moreImage->SmallImage->URL;
            }
        }

        $item_shipping_holder = array(
        'standard'=>$standard_shipping, 
        'expedited'=>$expedited_shipping, 
        'twoday'=>$twoday_shipping, 
        'oneday'=>$oneday_shipping);

        $item_holder[] = array(
        'default_image'=>$item_image_medium, 
        'category'=>$item->ItemAttributes->ProductGroup, 
        'title'=>$item->ItemAttributes->Title, 
        'asin'=>$item->ASIN, 
        'weight'=>$rounded_weight, 
        'description'=>$product_description, 
        'features'=>$item_feature_holder, 
        'shipping'=>$item_shipping_holder, 
        'image'=>$item_imagesets_holder);

    }

In my dump the first array was ok but in my second array, in the features and images part it repeats the data from the first one.

Here’s the var_dump of my array:

   array (size=9)
  'default_image' => string 'http://ecx.images-amazon.com/images/I/21pp4CsKwdL._SL160_.jpg' (length=61)
  'category' => string 'Personal Computer' (length=17)
  'title' => string 'MSI Computer Corp. Notebook Computer GE60 0NC-006US;9S7-16GA11-006 15.6-Inch Laptop' (length=83)
  'asin' => string 'B007YDHLYE' (length=10)
  'weight' => float 10.4
  'description' => string 'MSI GE60 0NC-006US 15.6 inch Core i7-3610QM 2.3GHz/6GB DDR3/750GB HDD/DVD Super Multi/USB3.0/W7HP Notebook Computer (Black/Red)' (length=127)
  'features' => 
    array (size=5)
      0 => string '3rd Generation Intel® Core™ i7 3610QM @2.3GHz. Intel® HM76 Chipset.' (length=71)
      1 => string '6GB (1x4GB + 1x2GB) SO-DIMM RAM, Max. 16GB. 750GB 7200rpm Hard Drive (With m-SATA port)' (length=87)
      2 => string '15.6" Full HD (1920x1080) LED backlight, Anti-glare screen. NVIDIA GeForce GTX650M 2GB GDDR5 with Optimus technology. 4(2Wx4)HD Speakers, THX True Studio Pro.' (length=158)
      3 => string 'Keyboard by SteelSeries, 103 keys. HD Webcam (30fps@720p). Wireless LAN 802.11 b/g/n. Bluetooth 4.0' (length=99)
      4 => string 'Windows 7 Home Premium 64-bit' (length=29)
  'shipping' => 
    array (size=4)
      'standard' => string '$9.69' (length=5)
      'expedited' => string '$16.79' (length=6)
      'twoday' => string 'N/A' (length=3)
      'oneday' => string 'N/A' (length=3)
  'image' => 
    array (size=5)
      0 => string 'http://ecx.images-amazon.com/images/I/21pp4CsKwdL._SL75_.jpg' (length=60)
      1 => string 'http://ecx.images-amazon.com/images/I/21OHSB3BiyL._SL75_.jpg' (length=60)
      2 => string 'http://ecx.images-amazon.com/images/I/211kjZnCiFL._SL75_.jpg' (length=60)
      3 => string 'http://ecx.images-amazon.com/images/I/21TKV3LXBmL._SL75_.jpg' (length=60)
      4 => string 'http://ecx.images-amazon.com/images/I/11WG9GF3nPL._SL75_.jpg' (length=60)

array (size=9)
  'default_image' => string 'http://ecx.images-amazon.com/images/I/215zEm1MX8L._SL160_.jpg' (length=61)
  'category' => string 'Personal Computer' (length=17)
  'title' => string 'MSI Computer Corp. Notebook Computer GE70 0ND-033US;9S7-175611-033 17.3-Inch Laptop' (length=83)
  'asin' => string 'B0082JFD1W' (length=10)
  'weight' => float 11.95
  'description' => string 'MSI GE70 0ND-033US 17.3 inch Core i7-3610QM 2.3GHz/8GB DDR3/750GB HDD/USB 3.0/DVD+/-RW/W7HP Notebook Computer (Black)' (length=117)
  'features' => 
    array (size=10)
      0 => string '3rd Generation Intel® Core™ i7 3610QM @2.3GHz. Intel® HM76 Chipset.' (length=71)
      1 => string '6GB (1x4GB + 1x2GB) SO-DIMM RAM, Max. 16GB. 750GB 7200rpm Hard Drive (With m-SATA port)' (length=87)
      2 => string '15.6" Full HD (1920x1080) LED backlight, Anti-glare screen. NVIDIA GeForce GTX650M 2GB GDDR5 with Optimus technology. 4(2Wx4)HD Speakers, THX True Studio Pro.' (length=158)
      3 => string 'Keyboard by SteelSeries, 103 keys. HD Webcam (30fps@720p). Wireless LAN 802.11 b/g/n. Bluetooth 4.0' (length=99)
      4 => string 'Windows 7 Home Premium 64-bit' (length=29)
      5 => string 'Intel Core_i7_3610QM Processor 2.3GHz' (length=37)
      6 => string '8  GB SO-DIMM RAM' (length=17)
      7 => string '750GB 7200rpm  Hard Drive' (length=25)
      8 => string '17.3-Inch Screen, NVIDIA GeForce GTX660M' (length=40)
      9 => string 'Windows 7 Home Premium 64-bit' (length=29)
  'shipping' => 
    array (size=4)
      'standard' => string '$10.49' (length=6)
      'expedited' => string '$18.37' (length=6)
      'twoday' => string 'N/A' (length=3)
      'oneday' => string 'N/A' (length=3)
  'image' => 
    array (size=10)
      0 => string 'http://ecx.images-amazon.com/images/I/21pp4CsKwdL._SL75_.jpg' (length=60)
      1 => string 'http://ecx.images-amazon.com/images/I/21OHSB3BiyL._SL75_.jpg' (length=60)
      2 => string 'http://ecx.images-amazon.com/images/I/211kjZnCiFL._SL75_.jpg' (length=60)
      3 => string 'http://ecx.images-amazon.com/images/I/21TKV3LXBmL._SL75_.jpg' (length=60)
      4 => string 'http://ecx.images-amazon.com/images/I/11WG9GF3nPL._SL75_.jpg' (length=60)
      5 => string 'http://ecx.images-amazon.com/images/I/215zEm1MX8L._SL75_.jpg' (length=60)
      6 => string 'http://ecx.images-amazon.com/images/I/21dAgtNONpL._SL75_.jpg' (length=60)
      7 => string 'http://ecx.images-amazon.com/images/I/21Buy-UDJoL._SL75_.jpg' (length=60)
      8 => string 'http://ecx.images-amazon.com/images/I/11LWf2AYqeL._SL75_.jpg' (length=60)
      9 => string 'http://ecx.images-amazon.com/images/I/11KuBpuL6NL._SL75_.jpg' (length=60)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:09:30+00:00Added an answer on June 13, 2026 at 12:09 pm

    Try resetting the holder arrays during each iteration of the for loop

    foreach($response->Items->Item as $item){
      $item_feature_holder   = array();
      $item_imagesets_holder = array();
      // rest of your code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add an additional value into an array before passing it to
Regarding passing arrays to functions and then manipulating the array contents (Array.Reverse) and then
I'm working with third-party COM object that has some of its methods passing values
jQuery tiny PubSub is great when passing primitive values or objects, but has some
I'm passing an array from my Rails app to Javascript via a js.erb template.
Thanks, I am passing in the array via json now and setting datatype to
Which is right? notice in the second option, I'm passing the form values using
array_unique is to be used by passing the array name as a parameter. But
Is it possible to open another PHP file (print_array.php) passing $array via PHP function?
I want to know what the best practice is for passing values (sometimes multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.