I have many product-pages, each page has a field labled »size« (inside a structure field). I’d like to create an array containing all available sizes, without containing duplicates.
My approach was to initialise an empty array, then iterate over a collection of all product-pages and push a page’s size-field value into the array, after checking if the array does not already contain the value (i.e. the value is only pushed if its not contained in the array, at least that’s the idea). My code:
The structure field actually only contains one entry, with a size. My question is based on the Kirby Shopify plugin which comes with a blueprint for products. The blueprint puts all variants of a Shopify product (received via web hook) into a structure field. In my special case, there is only one size/variant of each product (hence the structure field with a single entry).
In the end, I was able to get what I needed by using the array_unique method: