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);
4
  • Show the original array exactly, or the answer in the post mentioned should work. Commented Mar 20, 2014 at 5:35
  • @xdazz please refer top array set. this is what i get as a result array. Commented Mar 20, 2014 at 5:37
  • so you got twos arrays at first? Commented Mar 20, 2014 at 5:38
  • @xdazz yes. i'm using Advanced custom field repeater. and it gives an array like this. Commented Mar 20, 2014 at 5:39

4 Answers 4

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)); 
Sign up to request clarification or add additional context in comments.

Comments

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);

2 Comments

what do you mean by $array1, $array2? can convert your code into example given by me
$array1 = array( 0 => 'outdoor', 1 => 'indoor' ); $array2 = array( 0 => 'indoor' );
2
$array = array(array("outdoor","indoor"),array("indoor"));

$result = array_unique($array);

print_r($result[0]);

Demo

Comments

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

2 Comments

this works. but does not answer my question
I edit my post. Pl try this ... Pl accept this answer if works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.