Tick Twitch
Tick Twitch

Reputation: 566

Remove duplicates in each respective row of a 2d array

How can I remove duplicates from each subset in my 2d array?

Array
(
      [success] => Array
         (
            [0] => Done.
            [1] => Done.
         )

      [error] => Array
         (
            [0] => This request has already been processed.
            [1] => This request has already been processed.
            [2] => This request has already been processed.
            [3] => You Don't Have Permission.
            [4] => You Don't Have Permission.
         )

      [warning] => Array
         (
         )

)

As you can see on [error] and [success] array there is 2/3 same value on different key. Now What can i do? to keep only one. Like the below one


Array
(
      [success] => Array
         (
            [0] => Done.
         )

      [error] => Array
         (
            [0] => This request has already been processed.
            [1] => You Don't Have Permission.
         )

      [warning] => Array
         (
         )

)

Upvotes: 0

Views: 240

Answers (1)

The fourth bird
The fourth bird

Reputation: 163342

For your example data you might use array_map with array_unique.

$result = array_map("array_unique", $arrays);

Upvotes: 5

Related Questions