Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$string =
'ArtNo,Name,Color,Size
DEF270, Fingal, Stellar, 3XL
DEF270, Fingal, White, 4XL';
$data = str_getcsv($string, "\n");
foreach($data as $row) {
$rows[] = str_getcsv($row);
}
$res = array_reduce(
$rows,
function($res, $row) {
if (isset($res[$row[0]])) {
$res[$row[0]][1] .= ", $row[1]";
$res[$row[0]][2] .= ", $row[2]";
$res[$row[0]][3] .= ", $row[3]";
}
else $res[$row[0]] = $row;
return $res;
},
[]
);
var_export($res);