Inside a for
loop I have the following code which pushes an array that contains some data inside another array:
$finCombo = array("color" => $color, "size" => $size, "productID" => $theProductID."-".$color, "imageURL" => 'https://click-tshirt.gr/images/detailed/all/'.$theProductCode."_".strtolower($color).'.jpg', "productURL" => $theProductURL, "title" => $theProductName, "price" => $theProductPrice, "category_path" => $theCategoryName, "availability" => $theProductAvailability, "brand" => $theProductBrand, "SKU" => $theProductCode."-".$color);
array_push($finalCmb, $finCombo);
The goal is to create an XML file using the data from the array. The code should return an xml file that looks like the below example:
<store>
<date>2017-09-22 19:30</date>
<products>
<product>
<SKU>10206-BLACK</SKU>
<productID>338-BLACK</productID>
<size>Small, Medium, Large, X Large</size>
<color>BLACK</color>
<title>Women's Jersey Short Sleeve Deep V-Neck Tee BLACK</title>
<productURL>https://click-tshirt.gr/el-4/t-shirt-el/womens-jersey-short-sleeve-deep-v-neck-tee/</productURL>
<imageURL>https://click-tshirt.gr/images/detailed/all/10206_Black.jpg</imageURL>
<price>9.90</price>
<category_path>ΓΥΝΑΙΚΕΙΑ///T-SHIRT</category_path>
<brand>BELLA&CANVAS</brand>
<availability>Κατόπιν παραγγελίας</availability>
</product>
Here an example of the array where you can see that "425-DEEP_NAVY" is inserted in the array with the size "Medium" but later on it is inserted again and again for each size:
Array ( [0] => Array ( [0] => Array ( [color] => BLACK_DARK_GREY [size] => Small [productID] => 390-BLACK_DARK_GREY [imageURL] => https://click-tshirt.gr/images/detailed/all/18608_black_dark_grey.jpg [productURL] => http://click-tshirt.gr/el-3/category-50/adult-fashion-basic-ls-hooded-tee/ [title] => Adult Fashion Basic LS Hooded Tee [price] => 13.800000 [category_path] => ΑΝΔΡΙΚΑ/ΦΟΥΤΕΡΑΚΙΑ ΜΕ ΚΟΥΚΟΥΛΑ [availability] => Κατόπιν παραγγελίας [brand] => ANVIL [SKU] => 18608-BLACK_DARK_GREY )))
There is also one thing that happens and so far I have managed to resolve it with JavaScript. That is the products are inserted in the array for every "productID" there is several "size's" so for each size the same productID is inserted several times while what I need is that for each productID the size to be an array containing all sizes that correspond to that productID. See codepen console below: