Home > Backend Development > PHP Tutorial > php-遍历json数据,对相同数据进行分组?

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

WBOY
Release: 2016-06-02 11:31:25
Original
1362 people have browsed it

遍历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>
Copy after login
<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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template