You can also merge the functions 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 the map
with unique
:
$arr = array_map("unserialize", array_unique(array_map("serialize", $fromSQL)));
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
It’s value, not index, I edited the question.
– ElvisP
Add more information and it’s not clear what you need to do. I understand you try to compare the data but I don’t understand the logic, please explain better so we can help.
– Luigi Matheus
this variable
$arr
would be to save the array? ie, would not be$arr[]
?– novic
Resolve this in your SQL !!!
– novic
It’s a third-party trial, I’m implementing PHP only, and I don’t have access to the trial, I just get the list of procedures.
– ElvisP
I disagree, what I need is to generate an array, not remove duplicate from an existing array.
– ElvisP