2

How can I remove duplicate values from a multidimensional array in PHP like below.

I tried Remove duplicate value in multidimensional array. But did not solve my problem.

Array(
    [0] => outdoor
    [1] => indoor
)

Array(
    [0] => indoor
)

Result should be a single array like below :

 array(outdoor,indoor);
Community
  • 1
  • 1
Mahesh
  • 872
  • 1
  • 10
  • 25

4 Answers4

6

finally i found the result from Remove duplicate value in multidimensional array. I'll share them for other users.

$result = array_unique(call_user_func_array('array_merge',$result2)); 
Community
  • 1
  • 1
Mahesh
  • 872
  • 1
  • 10
  • 25
3

Use array_unique to remove duplicates from a single array.

Use array_merge to combine arrays.

Try:

array_unique(array_merge($array1,$array2), SORT_REGULAR);

tchow002
  • 1,068
  • 6
  • 8
2
$array = array(array("outdoor","indoor"),array("indoor"));

$result = array_unique($array);

print_r($result[0]);

Demo

AyB
  • 11,609
  • 4
  • 32
  • 47
Mad Angle
  • 2,347
  • 1
  • 15
  • 33
2

Try this:

<?php
$Arr = array(array('outdoor','indoor'),array('indoor'));
$result = array_unique($Arr);

$newArr = $result[0];

echo '<pre>';
print_r($newArr);
?>

The result will be

Array
(
    [0] => outdoor
    [1] => indoor
)

--

Thanks

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27