php - 在子数组中搜索
问题描述
我有我得到的数组
$article_foundd = Article::all();
数组本身
"["meta_title"]=> string(5) "sport"
["meta_description"]=> string(4) "NEWS"
["meta_keyword"]=> string(7) "sport, olimp"
"["meta_title"]=> string(7) "climate"
["meta_description"]=> string(14) "Climate change"
["meta_keyword"]=> string(19) "climate,weather,rain"
"["meta_title"]=> string(7) "box"
["meta_description"]=> string(19) "box"
["meta_keyword"]=> string(7) "sport,box,roy,tyson"
例如,我需要当一个人在搜索栏中输入“运动”时,将显示所有与运动相关的文章。全部搜索meta_keywords
目前我已经实现了一个元标题,但我需要使用键。
$q = Input::get ( 'q' );
$article_found = Article::where('meta_title','LIKE','%'.$q.'%')->get();
if(count($article_found) > 0)
return view('blog.search')->withDetails($article_found)->with('details' =>$article_found);
解决方案
试试这个示例查询,按字段搜索项目meta_keyword
$article_found = Article::where('meta_keyword','LIKE','%'.$q.'%')->get();
推荐阅读
- css - 给定这些类,这些 div 在 css 中会是什么颜色,为什么?
- haskell - 术语级访问时钟速率
- debugging - z390 断点、文件、parmfield
- c++ - struct timespec 可以重复用于 nanosleep 吗?
- python-3.x - 通过 Python 中的相似值合并两个嵌套字典列表
- c++ - 对类的未定义引用,常见答案尚未解决
- android - 使用 4 个数字的 Android 插值器
- python - 为什么 line != "\n" or line != "\r\n" or line !="\r" 不能过滤空行?
- buildroot - Buildroot 可以在不构建 Linux 内核的情况下构建根文件系统吗?
- python - 为什么字典在python中不按插入顺序返回键?