Recent Posts

Showing posts with label bidimensional. Show all posts
Showing posts with label bidimensional. Show all posts

How to: Remove duplicated elements from a bidimensional array PHP

Example array:

Array
(
    [0] => Array
 (
     [0] => abc
     [1] => def
 )

    [1] => Array
 (
     [0] => ghi
     [1] => jkl
 )

    [2] => Array
 (
     [0] => mno
     [1] => pql
 )

    [3] => Array
 (
     [0] => abc
     [1] => def
 )

    [4] => Array
 (
     [0] => ghi
     [1] => jkl
 )

    [5] => Array
 (
     [0] => mno
     [1] => pql
 )

)
Here is another, another way. No intermediate variables are saved.

We used this to de-duplicate results from a variety of overlapping queries.

$input = array_map("unserialize", array_unique(array_map("serialize", $input)));