fork download
  1. <?php
  2.  
  3. $currentValues = [1, 2];
  4. $newValues = [1, 3, 1, 4, 2];
  5. $a = array();
  6. $checkValues = array_flip($currentValues);
  7. foreach($newValues as $v){
  8. if(!isset($checkValues[$v])){
  9. $a[] = $v;
  10. }
  11. }
  12. print_r(array_merge($currentValues, $a));
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)