$s =<<< JSON
[
{"title": "11111111","channel": {"country": "USA"}},
{"title": "222222222","channel": {"country": "UK"}},
{"title": "3333333","channel": {"country": "China"}}
]
JSON;
$json = json_decode($s);
$r = array_filter($json, function($json) { return $json->channel->country == "UK"; });
print_r($r);Array
(
[1] => stdClass Object
(
[title] => 222222222
[channel] => stdClass Object
(
[country] => UK
) ))
[
{"title": "11111111","channel": {"country": "USA"}},
{"title": "222222222","channel": {"country": "UK"}},
{"title": "3333333","channel": {"country": "China"}}
]
JSON;
$json = json_decode($s);
$r = array_filter($json, function($json) { return $json->channel->country == "UK"; });
print_r($r);Array
(
[1] => stdClass Object
(
[title] => 222222222
[channel] => stdClass Object
(
[country] => UK
) ))
解决方案 »
- 关于手册中的一段话
- php soap wdsl 接口问题。请大侠帮忙
- 请问这个是如何实现的,请高人指点。
- 请问怎么实现这样的功能
- 关于php中 SOCKET 从服务端返回客户端数据问题
- mysql_fetch_array(): 出错问题
- 怎样设置才能使PHP访问MySql4.1.7(Win2000+IIS,ISAPI方式)
- php怎么才能上传100M以上的文件?从多方面条件找解决方法:(,上传时间就要好久:(
- 这JB代码到底想干嘛?
- Apache中怎么设置不让某一个ip访问网站?
- 当PHP页面没加载完成时,用户点击刷新了,怎么结束上次没加载完成的页面而重新加载?
- php中如何获取以下动态生成的text控件的个数,并且如何获取每个控件的值。
$s =<<< JSON
[
{"title": "11111111","channel": {"country": "USA"}},
{"title": "222222222","channel": {"country": "UK"}},
{"title": "3333333","channel": {"country": "China"}}
]
JSON;
$json = json_decode($s,true);
foreach($json as $v){
if ($v['channel']['country'] == 'UK'){$arr[] = $v;}
}
echo '<pre>';print_r($arr);
Array
(
[0] => Array
(
[title] => 222222222
[channel] => Array
(
[country] => UK
) ))