2
How to group keys and identical values of an array?
There may be N arrays inside the array, you cannot add equal keys.
For example:
[attributes] => Array
(
[0] => Array
(
[title] => Cor
[type] => text
[values] => Array
(
[1] => Amarelo
)
)
[1] => Array
(
[title] => Cor
[type] => text
[values] => Array
(
[2] => Azul
)
)
[2] => Array
(
[title] => Largura
[type] => text
[values] => Array
(
[2] => Grande
)
)
Desired result:
[attributes] => Array
(
[0] => Array
(
[title] => Cor
[type] => text
[values] => Array
(
[1] => Amarelo
[2] => Azul
)
)
[2] => Array
(
[title] => Largura
[type] => text
[values] => Array
(
[2] => Grande
)
)
What is the difficulty? I don’t understand.
– Jorge B.
Do dynamically, being that the array can change, I need to group only when the
title
andtype
are equal, color and width are examples, but can come any value, when equal, group thevalues
.– Marcelo Aymone
You do an insert function on
array
, compare thetitle
with existing ones and if there is an equal adds to thevalues
– Jorge B.
That’s where I’m catching rsrrsrsrsrs, I’m stuck on it. rs
– Marcelo Aymone
It is you who create the right array?
– Jorge B.
No, it comes from the comic book, can have 0 or 1000 results.
– Marcelo Aymone
It is complicated to do this without consuming great resources... When I get home I see.
– Jorge B.
Then it seemed simple when I looked. rs
– Marcelo Aymone