如何从两个数组中删除重复元素

时间:2017-10-16 12:04:09

标签: php

这是我的数组

(
    "userServiceIds": "1,2,3",
    "enggServiceIds": "4,5,6,2,1"
)

因为"userServiceIds"必须与"enggServiceIds"进行交叉检查,"enggServiceIds"必须与"userServiceIds"交叉检查

因为OUTPUT只需要

"userServiceIds": "1,2,3"
"enggServiceIds": "4,5,6"

1 个答案:

答案 0 :(得分:3)

也许您正在寻找array_diff

$data = [
    'userServiceIds' => [1,2,3],
    'enggServiceIds' => [4,5,6,2,1]
];

$data['enggServiceIds'] = array_diff($data['enggServiceIds'], $data['userServiceIds']);