2

I have two php arrays:

$array_1 = array(1,6,7,8);
$array_2 = array(1,5,3,4,7,8);

I want output like this:

$array_3 = array(1,6,7,8,5,3,4);

It means that third array should contain all values of first array and then remaining all values which are not inside first array.

0

1 Answer 1

2

Use array_merge and array_unique

<?php
$array_1 = array(1,6,7,8);
$array_2 = array(1,5,3,4,7,8);
$array_3 = array_unique(array_merge($array_1,$array_2));
var_dump($array_3);

Output:

array(7) {
  [0]=>
  int(1)
  [1]=>
  int(6)
  [2]=>
  int(7)
  [3]=>
  int(8)
  [5]=>
  int(5)
  [6]=>
  int(3)
  [7]=>
  int(4)
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.