Rumah >pembangunan bahagian belakang >tutorial php >php-遍历json数据,对相同数据进行分组?

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

WBOY
WBOYasal
2016-06-02 11:31:251348semak imbas

遍历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的数据,具体的操作我还是有些不太清楚

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn