PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?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);
Show:  
Copy Clear