$row['data'], 'excelrow' => [$row['excelrow']], 'style_codes' => [], 'style_descriptions' => [] ]; } else { $grouped_data[$key]['excelrow'][] = $row['excelrow']; } // Separa il valore in action2 (STYLE CODE + STYLE DESCRIPTION) $action2_value = $row['data'][$action2_index] ?? ''; if (!empty($action2_value)) { $parts = explode(' - ', trim($action2_value)); $style_code = $parts[0] ?? ''; $style_description = $parts[1] ?? ''; if (!empty($style_code)) { $grouped_data[$key]['style_codes'][] = $style_code; } if (!empty($style_description)) { $grouped_data[$key]['style_descriptions'][] = $style_description; } } else { error_log("Valore vuoto in action2 per excelrow {$row['excelrow']}"); } } // Crea il nuovo array excel_data aggregato $new_excel_data = []; foreach ($grouped_data as $key => $group) { $row_data = $group['data']; // Aggiorna action3 (STYLE CODE) e action4 (STYLE DESCRIPTION) con valori aggregati $row_data[$action3_index] = implode(' - ', array_unique($group['style_codes'])); $row_data[$action4_index] = implode(' - ', array_unique($group['style_descriptions'])); // Concatena gli excelrow con '+' per le righe aggregate $excelrow_value = count($group['excelrow']) > 1 ? implode('+', $group['excelrow']) : $group['excelrow'][0]; $new_excel_data[] = [ 'data' => $row_data, 'excelrow' => $excelrow_value ]; } // Modifica excelData in-place $excelData = $new_excel_data; error_log("Routine Moncler completata - Righe aggregate: " . count($new_excel_data)); error_log("Excelrow aggregati: " . print_r(array_column($new_excel_data, 'excelrow'), true)); } catch (Exception $e) { error_log("Eccezione nella routine Moncler: " . $e->getMessage()); throw $e; } }