db->get_where_in('ds_amazon_option', ['asin' => $optionsASIN])->result(); foreach($options as $k => $opt) { $this->option_name = $option_name; $this->default_id = $default_id; $this->asin = $optionsASIN[$k]; $this->option_title = $opt->title; $this->img = $opt->img; $this->created_at = date('Y-m-d H:i:s'); if($this->isDBOption($db_options, $opt->asin)) { $this->db->where('asin', $opt->asin)->update('ds_amazon_option', $this); }else { $this->db->insert('ds_amazon_option', $this); } } } private function isDBOption($db_options, $asin) { foreach($db_options as $o) { if($o->asin == $asin) { return true; } } } }