首页 >后端开发 >php教程 >php-遍历json数据,对相同数据进行分组?

php-遍历json数据,对相同数据进行分组?

WBOY
WBOY原创
2016-06-02 11:31:251347浏览

遍历phpjson

<code> {    "module_list": [        {            "content": {                "module-type": "list-1",                "module": "list",                "type": "1",                "name": "职位列表 ",                "logo1": "imgurl1",                "title1": "baidu1",                "desc1": "hahahha1",                "url1": "www.baidu.com1",                "logo2": "imgurl2",                "title2": "baidu2",                "desc2": "hahahha2",                "url2": "www.baidu.com2",                "logo3": "imgurl3",                "title3": "baidu3",                "desc3": "hahahha3",                "url3": "www.baidu.com3",                "logo4": "",                "title4": "",                "desc4": "",                "url4": "",                "jobs": [                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:1"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:2"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:3"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:4"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:1"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:1"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:4"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:4"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:3"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:2"                    },                    {                        "name": "产品经理",                        "salary": "10k-15k",                        "url": "www.baidu.com",                        "desc": "广州",                        "mark": "group:2"                    }                ]            },        }    ]}</code>
<code>     public static function buildList($module){        $jobList2 = "";        if($module['jobs']){            foreach($module['jobs'] as $job){                $jobList2 .=                     <a class="post post2">{$job['name']}</a>                    <span class="salary">{$job['salary']}</span>                html;            }        }                return</code>

是这样的,我通过php语句对页面进行拼接,但从json获取数据的时候,按上面写拼出来的是全部 的数据,但是我想根据mark值输出显示一些特定的数据,比如只拼接group:1的数据,具体的操作我还是有些不太清楚

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn