首頁 >後端開發 >php教程 >php-遍历json数据,对相同数据进行分组?

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

WBOY
WBOY原創
2016-06-02 11:31:251348瀏覽

遍历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