0

Trying to sort this out in a display I am working on for hikashop in joomla. when a product has variants, it automatically inherits the parent images for each variant. so what i need to do is merge the images array into one, but only if they are duplicate images. when i print out the array, it looks like this, but is duplicated for each $variant and my diplay that i have coded will show each image:

Array
(
    [0] => stdClass Object
        (
            [file_id] => 623
            [file_name] => 
            [file_description] => 
            [file_path] => zinklogohoodie_black_greystitch.png
            [file_type] => product
            [file_ref_id] => 495
            [file_free_download] => 0
            [file_ordering] => 0
            [file_limit] => 0
        )

)

my code is this so far:

if(!empty($this->element->variants)):
    echo "this product has variants";
    foreach($this->element->variants as $variant):
        print("<pre>".print_r($variant->images,true)."</pre>");
    endforeach;    
elseif(empty($this->element->variants)):
    echo "this product has no variants";
endif;

how do i test for and then merge all instances of duplicate $variant->images as well as the non duplicates into a single array?

TEN Design
  • 717
  • 3
  • 13
  • 31
  • you can have a look at http://stackoverflow.com/questions/2165406/php-merge-duplicate-array-keys-in-a-multidimensional-array – user3470953 Apr 29 '14 at 16:35
  • can you be more specific on how you want the array to look like – CMPS Apr 29 '14 at 16:36
  • @AmirBawab it would need to be structured just like the array above once merged. – TEN Design Apr 29 '14 at 16:37
  • @www.sblog.in yes I read that page and i suppose what it doesnt explain is the how. im trying to grasp how it works. I need to be able to wrap my head around it versus just having a pre-written answer – TEN Design Apr 29 '14 at 16:42

0 Answers0