public function combos() { $product_id = null; if ($this->uri->segment(3) !== false) { $product_id = $this->uri->segment(3); } $variants = Thing::getVariants($product_id); $type_a = array(); $type_b = array(); //get all options foreach ($variants as $variant) { $fields = $variant->getFields(); $type_a[] = $fields['option2']->getValue(); $type_b[] = $fields['option3']->getValue(); } //remove duplicates $type_a = array_unique($type_a); $type_b = array_unique($type_b); foreach ($type_a as $a) { foreach ($type_b as $b) { $combos[] = Combo::load($a, $b); } } //encode json $comboJson = array(); foreach ($combos as $combo) { $comboJson[] = $combo->toJson(); } echo json_encode($comboJson, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_QUOT); }