Reputation: 289
I have this array posting to my controller:
Array
(
[id] => Array
(
[0] => 95
[1] => 69
)
)
I want:
Array(
[id] => 95
[id] => 69
)
As I am using CodeIgniter's $this->db->delete() function and it takes the array key value as the column for the WHERE clause. I have this code at the moment:
foreach($ids as $k => $v){
$formatIds['id'] = $v;
}
Which just gives me one of the rows and not the rest.
I then tried:
foreach($ids as $k => $v){
$formatIds['id'][] = $v;
}
But this gives me a MultiDimensional array...
Upvotes: 2
Views: 1119
Reputation: 212422
The answer to your question is "not possible": array keys must always be unique.
The answer to what you're trying to do is to use where_in()
:
$names = array(95,69);
$this->db->where_in('id', $names);
$this->db->delete('mytable');
Upvotes: 4