首页 > 学院 > 开发设计 > 正文

二维数组中取某一相同字段的值进行拼接字符串用于in查询

2019-11-11 02:34:35
字体:
来源:转载
供稿:网友

方法1:使用php自带的一个函数:array_column() ,该函数的作用是返回输入数组中某个单一列的值。

具体使用方法参见:http://www.vevb.com.cn/php/func_array_column.asp

举例:

$res = $gw_distribute_log->where("user_id = ".$distributor_id)->select(); $house_id = array_column($res, 'house_id'); $all_house_id = implode(",",$house_id);

方法2:通过foreach来实现

举例:

foreach($res as $k=>$v){ $house_id[] = $v['house_id']; $all_house_id = implode(",",$house_id); }

最后进行in查询:

举例:

$map['house_build_id'] = array ('in',$all_house_id); if($get_status != ''){ $data = array( 'status'=>$get_status, '_complex'=>$map, '_logic'=>'and', ); $count = $gw_distributor->where($data)->count();// 查询满足要求的总记录数 $Page = new /Think/Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25) $show = $Page->show();// 分页显示输出 $result = $gw_distributor->where($data)->order('addtime')->limit($Page->firstRow.','.$Page->listRows)->select();以上就是返回输入数组中某个单一列的值并进行查询。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表