php - 如何从 mysql 和 php 中的 json 数组中搜索数据?
问题描述
{"email": "afadf%40gmail.com",
"phone": "2525",
"rooms": "4",
"floors": "2",
"user_id": "2",
"ad_title": "sdafasfdasf",
"features": "['Elevator','Center Stairs']",
"car_space": "5",
"full_name": "adaf",
"sortOrder": "10000",
"build_year": "2018"
}
我想使用上述 json 格式搜索 features='Elevator' 的数据。
解决方案
你可以使用json_decode()
函数。此函数将从 JSON 返回一个数组。
前任:
$data = '{
"email": "afadf%40gmail.com",
"phone": "2525",
"rooms": "4",
"floors": "2",
"user_id": "2",
"ad_title": "sdafasfdasf",
"features": "['Elevator','Center Stairs']",
"car_space": "5",
"full_name": "adaf",
"sortOrder": "10000",
"build_year": "2018"
}';
$arr = json_decode($data);
//The $arr variable will be an array contains the data from $data variable
然后,您可以使用array_search()
功能进行搜索。一些参考资料:
推荐阅读
- mysql - 我想知道是否有更好的方法来编写这个查询(同一个表的多个连接)
- python - 删除至少包含一个重复值的行
- slack - 获取应用集成的 Slack 频道
- klipfolio - Klipfolio 组通过澄清
- python - 删除 NaN 并将剩余值合并到一列中
- php - 动态下拉值 Laravel 8
- fortran - 在 Fortran 90 中以 .gsd 格式编写输出文件
- r - 使用 R Shiny 将工作表添加到带有操作按钮的预先存在的 excel 文件中
- python - Django - 注释按日期分组的不同值的计数()
- xcode - RN 错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)