You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何比较元素数量不同的多维关联数组并过滤重复productID

问题描述

我有两个元素数量不固定的多维关联数组,无法确定数组A或B哪个元素更多。

原始数组

数组A

[0] => Array
    (
        [catID] => 65
        [discount] => 10
        [productID] => Array
            (
                [0] => 10887
                [1] => 8508
                [2] => 8350
            )

        [startDate] => 05/12/2022 12:00 am
        [endDate] => 10/12/2022 12:00 am
    )
[1] => Array
    (
        [catID] => 66
        [discount] => 10
        [productID] => Array
            (
                [0] => 13184
                [1] => 10707
                [2] => 8350
            )

        [startDate] => 10/12/2022 12:00 am
        [endDate] => 15/12/2022 12:00 am
    )

数组B

[0] => Array
    (
        [catID] => 72
        [discount] => 15
        [productID] => Array
            (
                [0] => 16239
                [1] => 16236
                [2] => 10887
                [3] => 13184
                [4] => 8524
                [5] => 13314
            )
        [startDate] => 12/12/2022 12:00 am
        [endDate] => 15/12/2022 12:00 am
    )

期望结果

处理后的数组A(移除所有在数组B的productID中存在的productID)

[0] => Array
    (
        [catID] => 65
        [discount] => 10
        [productID] => Array
            (
                [1] => 8508
                [2] => 8350
            )
        [startDate] => 05/12/2022 12:00 am
        [endDate] => 10/12/2022 12:00 am
    )
[1] => Array
    (
        [catID] => 66
        [discount] => 10
        [productID] => Array
            (
                [0] => 10707
            )
        [startDate] => 10/12/2022 12:00 am
        [endDate] => 15/12/2022 12:00 am
    )

数组B(无变化)

[0] => Array
    (
        [catID] => 72
        [discount] => 15
        [productID] => Array
            (
                [0] => 16239
                [1] => 16236
                [2] => 10887
                [3] => 13184
                [4] => 8524
                [5] => 13314
            )
        [startDate] => 12/12/2022 12:00 am
        [endDate] => 15/12/2022 12:00 am
    )

内容的提问来源于stack exchange,提问作者enc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 12:10:31