OK - I've added the sort
usort($test, fn($a, $b) => $b['itemCount']<=>$a['itemCount']); // sort descending itemCount
$seen = [];
foreach ($test as $k => &$rec) {
$rec['rolanID'] = array_diff($rec['rolanID'], $seen); // find new ids
if ($rec['rolanID']) { // if there are some new ones ...
$rec['itemCount'] = count($rec['rolanID']); // count them
$seen = array_merge($seen, $rec['rolanID']); // add the new ones to those already seen
}
else unset($test[$k]); // if no ids, remove the array item
}
and I now get this (no duplicate 123)...
Array
(
[0] => Array
(
[supplier] => TEST2 DEPO
[rolanID] => Array
(
[0] => 456
[1] => 188
[2] => 200
[3] => 123
)
[itemCount] => 4
)
[1] => Array
(
[supplier] => TEST DEPO
[rolanID] => Array
(
[1] => 234
)
[itemCount] => 1
)
[2] => Array
(
[supplier] => DIFFERENT DEPO
[rolanID] => Array
(
[0] => 897
[1] => 487
[2] => 100
)
[itemCount] => 3
)
)