-1

I have an array $result as such:

[0] => Array (
  [0] => Array (
    [itemid] => 1
    [name] => A
  )
  [1] => Array (
    [itemid] => 2
    [name] => B
  )
)
[1] => Array (
  [0] => Array (
    [itemid] => 3
    [name] => C
  )
  [1] => Array (
    [itemid] => 2
    [name] => B
  )
)

and an array $items as such:

[0] => Array (
  [itemid] => 2
  [name] => B
)
[1] => Array (
  [itemid] => 4
  [name] => D
) 

How do I remove all items from the $result array, that occur in the $items array? In this case, the $result would become:

[0] => Array (
  [0] => Array (
    [itemid] => 1
    [name] => A
  )
)
[1] => Array (
  [0] => Array (
    [itemid] => 3
    [name] => C
  )
)

Since the question is mostly code, here's some extra characters to make StackOverflow accept the question.

Pim
  • 445
  • 1
  • 8
  • 24

1 Answers1

1

I think this is what you want. (Not tested yet)

<?php
foreach ($result as $key => $array) {
    $result[$key] = array_diff($array, $items);
}

print_r($result);
Vũ Nhật Anh
  • 512
  • 5
  • 14