Как объединить значение массива в многомерном массиве?

Подскажите новичку как работать с массивов. Есть массив $arr_test в нем

array (
 0 => 
   array (
'id_product_attribute' => '60',
'attribute_name' => 'S',
'group_name' => 'Size',
'public_group_name' => 'Size',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   1 => 
   array (
'id_product_attribute' => '59',
'attribute_name' => 'M',
'group_name' => 'Size',
'public_group_name' => 'Size',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   2 => 
   array (
'id_product_attribute' => '57',
'attribute_name' => 'M',
'group_name' => 'Size',
'public_group_name' => 'Size',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   3 => 
   array (
'id_product_attribute' => '56',
'attribute_name' => 'XL',
'group_name' => 'Size',
'public_group_name' => 'Size',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   4 => 
   array (
'id_product_attribute' => '58',
'attribute_name' => 'XL',
'group_name' => 'Size',
'public_group_name' => 'Size',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   5 => 
   array (
'id_product_attribute' => '56',
'attribute_name' => 'Grey',
'group_name' => 'Color',
'public_group_name' => 'Color',
'group_type' => 'color',
'attribute_color' => '#AAB2BD',
   ),
   6 => 
   array (
'id_product_attribute' => '59',
'attribute_name' => 'Grey',
'group_name' => 'Color',
'public_group_name' => 'Color',
'group_type' => 'color',
'attribute_color' => '#AAB2BD',
   ),
   7 => 
   array (
'id_product_attribute' => '57',
'attribute_name' => 'Grey',
'group_name' => 'Color',
'public_group_name' => 'Color',
'group_type' => 'color',
'attribute_color' => '#AAB2BD',
   ),
   8 => 
   array (
'id_product_attribute' => '58',
'attribute_name' => 'Grey',
'group_name' => 'Color',
'public_group_name' => 'Color',
'group_type' => 'color',
'attribute_color' => '#AAB2BD',
   ),
   9 => 
   array (
'id_product_attribute' => '60',
'attribute_name' => 'Yellow',
'group_name' => 'Color',
'public_group_name' => 'Color',
'group_type' => 'color',
'attribute_color' => '#F1C40F',
   ),
   10 => 
   array (
'id_product_attribute' => '56',
'attribute_name' => '40x60cm',
'group_name' => 'Dimension',
'public_group_name' => 'Dimension',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   11 => 
   array (
'id_product_attribute' => '57',
'attribute_name' => '40x60cm',
'group_name' => 'Dimension',
'public_group_name' => 'Dimension',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   12 => 
   array (
'id_product_attribute' => '58',
'attribute_name' => '60x90cm',
'group_name' => 'Dimension',
'public_group_name' => 'Dimension',
'group_type' => 'radio',
'attribute_color' => '',
   ),
   13 => 
   array (
'id_product_attribute' => '59',
'attribute_name' => '60x90cm',
'group_name' => 'Dimension',
'public_group_name' => 'Dimension',
'group_type' => 'radio',
'attribute_color' => '',
   ),
 )

Так вот мне нужно добиться чтобы id_product_attribute которые повторяются удалялись но при этом attribute_name конкатенировался.

С горем пополам у меня это вышло

$result = array_reduce($arr_test, function($res, $el) {
            if (isset($res[$el["id_product_attribute"]])) {      
                          
              $res[$el["id_product_attribute"]] .= ", " . $el["attribute_name"];            
            } else {      
               $res[$el["id_product_attribute"]] = $el["attribute_name"];
            }    
            return $res;
              
        });

вывод

    array (
     60 => 'S, Yellow',
     59 => 'M, Grey, 60x90cm',
     57 => 'M, Grey, 40x60cm',
     56 => 'XL, Grey, 40x60cm',
     58 => 'XL, Grey, 60x90cm',
     )

Но теперь я нечего не могу сделать с остальными значениями. Вот что у меня получилось

введите сюда описание изображения

но когда я добавляю остальные атрибуты вот что получается

array (
 60 => 'S, Yellow',
 'Size' => 'Size',
 59 => 'M, Grey, 60x90cm',
 57 => 'M, Grey, 40x60cm',
 56 => 'XL, Grey, 40x60cm',
 58 => 'XL, Grey, 60x90cm',
 )

введите сюда описание изображения

Вопрос в следующем. Как атрибуты которые я буду еще добавлять в значение не влияли на вывод в фронт, так как указано на img, но я мог к ним обращаться???


Ответы (0 шт):