fork(12) download
  1. <?php
  2.  
  3. $a = array('a','b','a','c');
  4. $b = array('a');
  5.  
  6. $counts = array_count_values($b);
  7. $a = array_filter($a, function($o) use (&$counts) {
  8. return empty($counts[$o]) || !$counts[$o]--;
  9. });
  10.  
  11. print_r($a);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [1] => b
    [2] => a
    [3] => c
)