title: Loop through foreach statement and add into empty multi dimensional array
body: <p>I'm trying to populate an empty array with the name and value from a foreach loop. I've created an array <code>$variationimages = array();</code> and within the loop I'm saving the values by using <code>$variationimages['name']</code> and <code>$variationimages['image']</code>. </p>
  
  <p>When returning the <code>$variationimages</code> array I'm only getting the first item</p>
  
  <pre><code>Array
  (
      [name] = Wall Profile
      [image] = &lt;img src="example-image.jpg"&gt;
  )
  </code></pre>
  
  <p>What I would like is for it to return something like the below and to be able to access a specific item in the array by using something like <code>$variationimages['Roof Profile']['image']</code> which would return the image of the item with the name 'Roof Profile'.</p>
  
  <pre><code> Array
      (
          [name] = Wall Profile
          [image] = &lt;img src="example-image.jpg"&gt;
      ), 
  (
              [name] = Roof Profile
              [image] = &lt;img src="example-image.jpg"&gt;
          ),
  </code></pre>
  
  <p>The code I have is below:</p>
  
  <pre><code>function loop_display_variation_attribute_and_thumbnail() {
      global $product;
  
      // HERE your targeted product attribute taxonomy
      $taxonomy = 'pa_product_type';
      $variationimages = array();
  
      if( $product-&gt;is_type('variable') ) {
          foreach ( $product-&gt;get_available_variations() as $variation ) {
  
              if( isset($variation['attributes']['attribute_'.$taxonomy]) ) {
                  // Get the "pa_product_type"
                  $term_name = get_term_by('slug', $variation['attributes']['attribute_'.$taxonomy], $taxonomy)-&gt;name;
                  $term_slug = get_term_by('slug', $variation['attributes']['attribute_'.$taxonomy], $taxonomy)-&gt;slug;
  
                  $variationimages['name'] = get_term_by('slug', $variation['attributes']['attribute_'.$taxonomy], $taxonomy)-&gt;name;
                  $variationimages['image'] = '&lt;img style="display:none;" class="'.$term_slug.'-image" src="' . $variation['image']['thumb_src'] .'"&gt;';
              }
          }
          echo "&lt;div style='display:none'&gt;"; 
                  print_r($variationimages);
                  echo "&lt;/div&gt;";
      }
  }
  </code></pre>