3v4l.org

run code in 300+ PHP versions simultaneously
<?php $csv = [ ['s1','n1','description 1', 'Helmets'], ['s1','n1','description 1a', 'Helmets'], ['s2','n1','description 2', 'Gloves'], ['s2','n1','description 2a', 'Gloves'], ]; $catMap = [ 'Helmets' => 30, 'Gloves' => 20, ]; $result = []; foreach($csv as $row){ //#1 trimming: $row = array_map('trim', $row); $row = [ 'SKU' => $row[0], 'Product_Name' => $row[1], 'Description' => $row[2], 'Category_ID' => $row[3], ]; $sku = $row['SKU']; //#2 cat remapping assert(isset($catMap[$row['Category_ID']])); $row['Category_ID'] = $catMap[$row['Category_ID']]; //#3 combining if(isset($result[$sku])){ $result[$sku]['Description'] .= ' ' . $row['Description']; }else{ $result[$sku] = $row; } }; var_dump($result);
Output for git.master_jit, git.master, rfc.property-hooks
array(2) { ["s1"]=> array(4) { ["SKU"]=> string(2) "s1" ["Product_Name"]=> string(2) "n1" ["Description"]=> string(28) "description 1 description 1a" ["Category_ID"]=> int(30) } ["s2"]=> array(4) { ["SKU"]=> string(2) "s2" ["Product_Name"]=> string(2) "n1" ["Description"]=> string(28) "description 2 description 2a" ["Category_ID"]=> int(20) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.02 ms | 402 KiB | 8 Q