【问题标题】:How to check multiple values in an array in codeigniter?如何在codeigniter中检查数组中的多个值?
【发布时间】:2017-05-19 18:53:00
【问题描述】:

我想在 codeigniter 中检查数组中的多个值...

我只知道这个……

$vehicles = array('Car','Bike','Plane','Bus');
$this->db->where_in('Car,Bike', $vehicles);

请帮帮我... 提前谢谢...

【问题讨论】:

标签: php codeigniter


【解决方案1】:

我认为您正在寻找此代码

$vehicles = array('car'=>'car','bike'=>'bike');
$this->db->where_in($vehicles);

谢谢 用心尝试。它有效

【讨论】:

    【解决方案2】:

    我不太明白你的问题,但我认为你正在寻找这个:

    $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');
    

    【讨论】:

    • 先生,感谢您的回答...但是,我想检查车辆列中的汽车,自行车...我的意思是多个值...怎么做??
    【解决方案3】:

    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);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-21
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-21
      相关资源
      最近更新 更多