这里是
的示例$arr = json_decode('{"people":[
{
"id": "8080",
"content": "foo",
"member": [123, 456],
"interval": 7
},
{
"id": "8097",
"content": "bar",
"member": [1234, 4567],
"interval": 7
}
]}', true);
$searchId = 123;
$results = array_filter($arr['people'], function($people) use ($searchId) {
return in_array($searchId, $people['member']);
});
$final = json_encode($results);
echo $final;
这会打印[{“ id”:“ 8080”,“ content”:“ foo”,“ member”:[123,456],“ interval”:7}]
但是当我尝试获取某个元素的特定值(例如“内容”)时,它显示了一个非法的字符串偏移错误
echo $final["content"];
我应该怎么做才能显示“内容”的价值? (在这种情况下为“ foo”)
答案 0 :(得分:1)
将echo $final["content"];
更改为echo $results[0]["content"];
答案 1 :(得分:0)
实际上,您不需要let newArray = varNames.filter({!reservedWords.contains($0)})
直接输出到
$final = json_encode($results);