-2

I am facing Problem with removing the duplicate value from the multidimensional array.

 Array
 (
    [524] => Array
        (
            [0] => 526
            [1] => 530
            [2] => 528
            [3] => 528
        )

    [1100] => Array
        (
            [0] => 1126
            [1] => 1126
            [2] => 1126
            [3] => 1126
        )

    [1244] => Array
        (
            [0] => 1260
            [1] => 1266
            [2] => 1260
            [3] => 1260
        )

)

there are duplicates value in array. i want to remove them.

Needed Output will be

Array
(
    [524] => Array
        (
            [0] => 526
            [1] => 530
            [2] => 528
        )

    [1100] => Array
        (
            [0] => 1126
        )

    [1244] => Array
        (
            [0] => 1260
            [1] => 1266
        )

)
2
  • 1
    Please don't just ask us to solve the problem for you. Show us how you tried to solve the problem yourself, then show us exactly what the result was, and tell us why you feel it didn't work. Give us a clear explanation of what isn't working and provide a Minimal, Complete, and Verifiable example. Read How to Ask a good question. Be sure to take the tour and read this. Commented Sep 17, 2019 at 11:35
  • do :- foreach($array as &$arr){ $arr = array_unique($arr);}print_r($array);:- 3v4l.org/lBZJB Commented Sep 17, 2019 at 13:19

1 Answer 1

1
foreach($a as $k => &$v){
  $v = array_unique($v);
}

Working example :- https://3v4l.org/93LGY

Sign up to request clarification or add additional context in comments.

3 Comments

Please don't answer "Gimme code"-type questions. Answering them will just keep the OP and future visitors to keep asking.
@MagnusEriksson noted.
@RakeshJakhar much better approach:-foreach($array as &$arr){ $arr = array_unique($arr);}print_r($array);:- 3v4l.org/lBZJB

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.