通过过滤字符串数组的JSON PHP [英] filter json array php by string
本文介绍了通过过滤字符串数组的JSON PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用 json_de code()
来设置数据的JSON阵列。
I have a JSON array that uses json_decode()
to setup the data.
我在寻找相匹配的数组中某一个项目,如果它符合我需要返回数组的整个行,不只是单场像所有filter_array()的片段我发现。
I'm looking to match a certain item in the array and if it matches i need to return the entire "row" of the array, not just a single field like all of the filter_array() snippets i'm finding.
任何人都可以点我在正确的方向?
Can anyone point me in the right direction?
数据看起来像这样打电话之前 json_de code()
:
Data looks like this before calling json_decode()
:
[
{
"format": "default",
"media_url": "http://cpe.delvenetworks.com/000337/011911_redzonefull.mp3",
"title": "RZ - Jim Trotter",
"thumb_url": "",
"date_posted": "2011-01-19 14:58:45",
"media_type": "audio"
},
{
"format": "default",
"media_url": "http://cpe.delvenetworks.com/000337/f10bestof2010offense.mp4",
"title": "Best of O - 2010",
"thumb_url": "http://img.delvenetworks.com/bV7.120x66.jpeg",
"date_posted": "2011-01-18 16:01:45",
"media_type": "video"
},
{
"format": "default",
"media_url": "http://cpe.delvenetworks.com/000337\f10bestof2010defense.mp4",
"title": "Best od D - 2010",
"thumb_url": "http://img.delvenetworks.com/UqK.120x66.jpeg",
"date_posted": "2011-01-18 16:01:45",
"media_type": "video"
}
我需要匹配 MEDIA_TYPE
。
推荐答案
这样呢?
function filter($filter, $array){
$filtered_array = array();
for($i = 0; i < count(array); i++){
if($array[i].media_type == $filter)
$filtered_array[] = array[i]
}
return $filtered_array
}
这篇关于通过过滤字符串数组的JSON PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文