在CodeIgniter中的MySql WHERE子句中使用数组

时间:2016-01-07 22:53:41

标签: php mysql arrays codeigniter

我想从以下数组中获取conversation_id值并将它们存储到另一个数组中,以便我可以在WHERE子句中使用它。这可能吗?

`Array ( [conversation] => Array ( 
[0] => Array ( 
[conversation_id] => 4
[conversation_subject] => This is just a test 
[conversation_last_reply] => 2016-01-03 20:12:14 
[conversation_unread] => 1 ) 
[1] => Array (
[conversation_id] => 3 
[conversation_subject] => Interview scheduled for monday [conversation_last_reply] => 2016-01-03 18:51:33 
[conversation_unread] => 1 ) 
[2] => Array ( 
[conversation_id] => 2 
[conversation_subject] => Google hangout
[conversation_last_reply] => 2016 [conversation_unread] => 1 )
[3] => Array ( 
[conversation_id] => 1 
[conversation_subject] => testing 
[conversation_last_reply] => 2016
[conversation_unread] => 1 ) ) )`

我的框架工作是codeignitor

2 个答案:

答案 0 :(得分:1)

我建议您熟悉PHP的内置foreach()功能。

答案 1 :(得分:1)

您可以定义一个新数组,并使用conversation_id和 您将使用$this->db->where_in()来获得结果。

$where = [];
foreach($array['conversation'] as $row){
   $where[] = $row['conversation_id'];
}

//型号代码

$this->db->where_in('conversation_id', $where);

希望有所帮助。