Scenario:
- Item is shared to groups
[6,5]
- I want to edit item to share to groups
[5,4]
- in result,
6
will be remove and4
will be added while5
is as is
- in result,
<?php
$shared_groups = [6,5];
$group_ids = [5,4];
$new_groups = array_diff($group_ids, $shared_groups);
$as_is_groups = array_intersect($shared_groups, $group_ids);
$to_delete_groups = array_diff($shared_groups, $as_is_groups);
dd(
'inputs', array($shared_groups, $group_ids),
'new groups', $new_groups,
'existing', $as_is_groups,
'remove', $to_delete_groups
);