0

I have a variable for example $attribute which has the set of arrays that has same keys but different values which i want to merge as to have one key and pair it with all the values

Array
(
    [color] => #11f7d8
)
Array
(
    [color] => #75e3ff
)
Array
(
    [color] => #acff7c
)
Array
(
    [color] => #e996fa
)
Array
(
    [size] => s
)

the output of the above input should be as below, how to i do that

Array
(
    'color' => ['#11f7d8','#75e3ff','#acff7c','#e996fa'],
    'size'  => ['s']
)
RaZoo
  • 77
  • 7
  • $source = [['color'=> '#11f7d8'] ,['color' => '#75e3ff'],['color' => '#acff7c'],['color' => '#e996fa'], ['size' => 's']];. $result = ['color' => array_column($source, 'color'),'size' =>array_column($source, 'size')]; – D Coder Nov 08 '21 at 14:51

0 Answers0