Question: In case of one-dim array I can use `array_unique` to get unique entries. But which function should be used to work with two-dim arrays?
For instance:

```
Array[0][0] = '123'; Array[0][1] = 'aaa';
Array[1][0] = '124'; Array[1][1] = 'aaa';
Array[2][0] = '124'; Array[2][1] = 'aaa';

```

In the above example I need to delete non-unique rows based on column 0. As a result I should get first two entries, while the third entry should be deleted. How to do this?

Answer: 
If your array always returns the same value for column 1, when column 0 is repeated, you should use the flag SORT\_REGULAR on array\_unique, like this:

```
$matrix = array(
    array(0 => '123', 1 => 'aaa'),
    array(0 => '124', 1 => 'aaa'),
    array(0 => '124', 1 => 'aaa'),
);

var_dump(array_unique($matrix, SORT_REGULAR));

```
I have a couple of efficient techniques to share. ([Demo](https://3v4l.org/kCHOq))

If you don't care about the order of the results, this one-liner will preserve the first unique rows (based on the column value).

Code:

```
var_export(array_reverse(array_column(array_reverse($array), null, 0)));

```

This reverses the input and overwrites previously found rows with duplicate first column values -- because duplicates keys are not permitted in the same array level.

Or if you want to preserve the original order of rows, this will provide the same result without reversing.

Code:

```
$result = [];
foreach ($array as $row) {
    if (!isset($result[$row[0]])) {
        $result[$row[0]] = $row;
    }
}

var_export(array_values($result));

```

Using temporary keys and `isset()` is more efficient than `array_search()` because php is faster at searching for keys than values.