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

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

WBOY
Freigeben: 2016-06-02 11:31:25
Original
1356 Leute haben es durchsucht

遍历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>
Nach dem Login kopieren
<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>
Nach dem Login kopieren

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

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage