php - laravel where 条件数组查询
黄舟
黄舟 2017-04-11 10:28:38
[PHP讨论组]

现在有 这么一组数组,这个数组也是动态查询到的

$categories = [1,2,3,4];

通过这个数组 在查询

Posts = 1 或者 = 2 或者 = 3 或者 = 4

难道要写 foreach

$A = [];
foreach ($arrs as $v) {
    $posts =  Post::where('category_id',$v)->get();
    
    array_merge($A, $posts); // 这样合并会出现 2层 ,因为本身 $posts 就是数组集合了 ,$A 该如何直接得到 $posts 总集合呢
}

求大神 妙计, 查询 多个 category_idposts

大神快出现吧 xixi

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

全部回复(2)
伊谢尔伦
$categories = [1,2,3,4];

$posts = Post::whereIn('category_id',$categories)->get();


whereIn 搞定了 
黄舟

laraval whereIn('field',$conditionArr);

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号