【发布时间】:2017-05-19 18:53:00
【问题描述】:
我想在 codeigniter 中检查数组中的多个值...
我只知道这个……
$vehicles = array('Car','Bike','Plane','Bus');
$this->db->where_in('Car,Bike', $vehicles);
请帮帮我... 提前谢谢...
【问题讨论】:
标签: php codeigniter
我想在 codeigniter 中检查数组中的多个值...
我只知道这个……
$vehicles = array('Car','Bike','Plane','Bus');
$this->db->where_in('Car,Bike', $vehicles);
请帮帮我... 提前谢谢...
【问题讨论】:
标签: php codeigniter
我认为您正在寻找此代码
$vehicles = array('car'=>'car','bike'=>'bike');
$this->db->where_in($vehicles);
谢谢 用心尝试。它有效
【讨论】:
我不太明白你的问题,但我认为你正在寻找这个:
$vehicles = array('Car','Bike','Plane','Bus');
$this->db->where_in('vehicle', $vehicles); //assuming vehicle is the name of a
//column in your database. Result will be:
// WHERE vehicle IN ('Car', 'Bike', 'Plane', 'Bus');
【讨论】:
和https://www.codeigniter.com/userguide3/database/query_builder.html 一样,where_in 中的第一个参数应该是表列名。
根据你最后的评论:你可以用array_slice
函数获取数组的前两个元素:$vehicles = array('Car','Bike','Plane','Bus');
$slicedArray = array_slice($vehicles, 0, 2);
$this->db->where_in('column_name', $slicedArray);
【讨论】: