登录  /  注册
大神们求解,这个数组对比怎么处理
小萝卜头
小萝卜头 2020-06-30 16:33:24
[PHP讨论组]

问题:我想要的是一个数组的pid,存不存在第二个数组里,如果少了或者多了就返回个错误。如果都有的话,第一个数组的id是第二个数组的childer的id,如果他们相等的话,将第二数组的其余的childer都去掉只保留相等的;

数组1:

Array

(

    [0] => Array

        (

            [pid] => 47

            [id] => 48

        )

    [1] => Array

        (

            [pid] => 52

            [id] => 54

        )

    [2] => Array

        (

            [pid] => 55

            [id] => 56

        )

    [3] => Array

        (

            [pid] => 58

            [id] => 60

        )

    [4] => Array

        (

            [pid] => 63

            [id] => 65

        )

)

数组2:

Array

(

    [0] => Array

        (

            [id] => 47

            [pid] => 0

            [type] => 2

            [attribute_name] => 渠道

            [childer] => Array

                (

                    [0] => Array

                        (

                            [id] => 48

                            [pid] => 47

                            [type] => 2

                            [attribute_name] => 大陆国行

                            [price_percentage] => 2%

                        )

                    [1] => Array

                        (

                            [id] => 49

                            [pid] => 47

                            [type] => 2

                            [attribute_name] => 港澳台版

                            [price_percentage] => 2%

                        )

                    [2] => Array

                        (

                            [id] => 50

                            [pid] => 47

                            [type] => 2

                            [attribute_name] => 其他国家地区-无锁版

                            [price_percentage] => 2%

                        )

                    [3] => Array

                        (

                            [id] => 51

                            [pid] => 47

                            [type] => 2

                            [attribute_name] => 其他国家地区-有锁版

                            [price_percentage] => 2%

                        )

                )

        )

    [1] => Array

        (

            [id] => 52

            [pid] => 0

            [type] => 2

            [attribute_name] => 苹果保修时长

            [childer] => Array

                (

                    [0] => Array

                        (

                            [id] => 53

                            [pid] => 52

                            [type] => 2

                            [attribute_name] => 保修期剩余大于1个自然月

                            [price_percentage] => 2%

                        )

                    [1] => Array

                        (

                            [id] => 54

                            [pid] => 52

                            [type] => 2

                            [attribute_name] => 过保或保修期小于1个自然月

                            [price_percentage] => 2%

                        )

                )

        )

    [2] => Array

        (

            [id] => 55

            [pid] => 0

            [type] => 2

            [attribute_name] => 型号

            [childer] => Array

                (

                    [0] => Array

                        (

                            [id] => 56

                            [pid] => 55

                            [type] => 2

                            [attribute_name] => A1863全网通

                            [price_percentage] => 2%

                        )

                    [1] => Array

                        (

                            [id] => 57

                            [pid] => 55

                            [type] => 2

                            [attribute_name] => 其他

                            [price_percentage] => 2%

                        )

                )

        )

    [3] => Array

        (

            [id] => 58

            [pid] => 0

            [type] => 2

            [attribute_name] => 机身颜色

            [childer] => Array

                (

                    [0] => Array

                        (

                            [id] => 59

                            [pid] => 58

                            [type] => 2

                            [attribute_name] => 金色

                            [price_percentage] => 2%

                        )

                    [1] => Array

                        (

                            [id] => 60

                            [pid] => 58

                            [type] => 2

                            [attribute_name] => 白色

                            [price_percentage] => 2%

                        )

                    [2] => Array

                        (

                            [id] => 61

                            [pid] => 58

                            [type] => 2

                            [attribute_name] => 黑色

                            [price_percentage] => 2%

                        )

                    [3] => Array

                        (

                            [id] => 62

                            [pid] => 58

                            [type] => 2

                            [attribute_name] => 红色

                            [price_percentage] => 2%

                        )

                )

        )

    [4] => Array

        (

            [id] => 63

            [pid] => 0

            [type] => 2

            [attribute_name] => 存储容量

            [childer] => Array

                (

                    [0] => Array

                        (

                            [id] => 64

                            [pid] => 63

                            [type] => 2

                            [attribute_name] => 256G

                            [price_percentage] => 2%

                        )

                    [1] => Array

                        (

                            [id] => 65

                            [pid] => 63

                            [type] => 2

                            [attribute_name] => 128G

                            [price_percentage] => 2%

                        )

                    [2] => Array

                        (

                            [id] => 66

                            [pid] => 63

                            [type] => 2

                            [attribute_name] => 64G

                            [price_percentage] => 2%

                        )

                )

        )

)

小萝卜头
小萝卜头

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号