You can also merge array_map
and array_unique
:
$fromSQL = [
[
'empresa' => 'abc',
'cnpj' => 72905498000142
],
[
'empresa' => 'abc',
'cnpj' => 72905498000142
],
[
'empresa' => 'ghi',
'cnpj' => 21808437000126
],
[
'empresa' => 'jkl',
'cnpj' => 19107168000129
],
[
'empresa' => 'mno',
'cnpj' => 65566224000100
]
];
You would have the result:
array (size=5)
0 =>
array (size=2)
'empresa' => string 'abc' (length=3)
'cnpj' => int 72905498000142
1 =>
array (size=2)
'empresa' => string 'abc' (length=3)
'cnpj' => int 72905498000142
2 =>
array (size=2)
'empresa' => string 'ghi' (length=3)
'cnpj' => int 21808437000126
3 =>
array (size=2)
'empresa' => string 'jkl' (length=3)
'cnpj' => int 19107168000129
4 =>
array (size=2)
'empresa' => string 'mno' (length=3)
'cnpj' => int 65566224000100
Applying map
to unique
:
$arr = array_map("unserialize", array_unique(array_map("serialize", $fromSQL)));
It would result in:
array (size=4)
0 =>
array (size=2)
'empresa' => string 'abc' (length=3)
'cnpj' => int 72905498000142
2 =>
array (size=2)
'empresa' => string 'ghi' (length=3)
'cnpj' => int 21808437000126
3 =>
array (size=2)
'empresa' => string 'jkl' (length=3)
'cnpj' => int 19107168000129
4 =>
array (size=2)
'empresa' => string 'mno' (length=3)
'cnpj' => int 65566224000100