php - MongoDB 使用 PHP 搜索文档并查找值
问题描述
我有以下 json 数据:
{
"name" : "Template1",
"data" : {
"columns" : [
{
"name" : "Brand Size",
"record" : [
{
"fname" : "column_search",
"fields" : [
{
"name" : "column_search_form_search",
"value" : "332"
},
],
"rules" : [
{
"rules_info_cond" : "if",
}
]
},
{
"name" : "vendorArticleName",
"record" : [
{
"fname" : "column_search",
"rules" : [
{
"rules_info_cond" : "if",
}
]
},
{
"name" : "Remarks",
"record" : [
{
"fname" : "column_information_show",
"rules" : [
[
]
]
},
}
我想获取具有 fname = 'column_information_show' 的 data->columns->name 我能够使用 MongoDB 找到但无法使用 PHP 找到。请帮帮我!
解决方案
$array = json_decode($jsonData, true);
foreach($array['data']['columns'] as $value) {
if($value['record']['fname'] == 'column_information_show'){
return $value;
}
}
这将遍历您的 json 数据并返回 fname 等于 column_information_show 的第一列。如果要返回多列,可以将它们添加到数组中,然后稍后返回。
推荐阅读
- java - 无法使用 Java JDBC 连接到 MySQL 数据库
- git - git cvsimport:“远程”指的是什么?
- java - 动态更新实时事件的文本字段
- php - 仅图像上的 curl 身份验证错误
- sql-server - MSSQL中的差异比较运算符
- python - PYOMO 电子表格阅读问题
- python - 使用 Pandas 或 csv python 从 csv 中删除不明确的行
- r - searchconsoleR 中的谷歌搜索控制台 API 正则表达式
- java - JavaFX tableview 可编辑单元格
- google-fabric - 获取多个游戏的崩溃、% 等的 Fabric API