Pass array to where in Codeigniter Active Record Pass array to where in Codeigniter Active Record codeigniter codeigniter

Pass array to where in Codeigniter Active Record


$this->db->where_in('id', ['20','15','22','42','86']);

Reference: where_in


Use where_in()

$ids = array('20', '15', '22', '46', '86');$this->db->where_in('id', $ids );


From the Active Record docs:

$this->db->where_in();

Generates a WHERE field IN ('item', 'item') SQL query joined with AND if appropriate

$names = array('Frank', 'Todd', 'James');$this->db->where_in('username', $names);// Produces: WHERE username IN ('Frank', 'Todd', 'James')