public function save() { $data = $this->post(); $count = count($data['tax_name']); $index = 0; $taxes = array(); while ($count > $index) { if ($data['tax_name'][$index] == 'xyz' || $data['tax_name'][$index] == '' || $data['tax_country'][$index] == '' || $data['tax_rate'][$index] == 0) { $index++; continue; } $tax['name'] = $data['tax_name'][$index]; $tax['country'] = $data['tax_country'][$index]; $tax['region'] = $data['tax_region'][$index]; $tax['rate'] = $data['tax_rate'][$index]; $taxes[] = $tax; $index++; } // empty all taxes then add all taxes sent $taxObj = new TaxObject(); $taxObj->deleteAll(); foreach ($taxes as $tax) { $taxObj->add($tax); } $this->redirect('/dashboard/razor/tax'); }