I have a multidimensional array and I'm trying to sort it by common value of one particular key, name in my case.
I already tried using a foreach to loop into the array, or using usort, but I just can't find the way to do it.
Notice how the values of the "Diamètre" key are merged into an array in the final result.
Array
(
[0] => Array
(
[0] => Array
(
[name] => Diamètre
[value] => 5
)
[1] => Array
(
[name] => Force
[value] => 30
)
)
[1] => Array
(
[0] => Array
(
[name] => Force
[value] => 20
)
[1] => Array
(
[name] => Poids
[value] => 50
)
)
[2] => Array
(
[0] => Array
(
[name] => Diamètre
[value] => 40
)
[1] => Array
(
[name] => Largeur
[value] => 40
)
)
)
Expected result :
Array
(
[0] => Array
(
[name] => Diamètre
[value] => Array (5, 40)
)
[1] => Array
(
[name] => Force
[value] => Array (30, 20)
)
[2] => Array
(
[name] => Poids
[value] => 50
)
[3] => Array
(
[name] => Largeur
[value] => 40
)
)