3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "S10.G00.00.001,'www.mywebsite.com'", "S10.G00.00.002,'Company name'", "S10.G00.00.003,'v2.01'", "S10.G00.01.001,'492484944'", "S10.G00.01.002,'00029'", "S10.G00.01.003,'First name'", "S10.G00.01.004,'120 R CHARLES'", "S10.G00.01.005,'92200'", "S10.G00.02.001,'01'", "S10.G00.02.002,'first name'", "S10.G00.02.004,'email@gmail.com'", "S10.G00.02.005,'0750000000'", "S20.G00.05.001,'01'", "S20.G00.05.002,'01'", "S20.G00.05.003,'11'", "S20.G00.05.004,'5'", "S20.G00.05.010,'01'", "S10.G00.01.001,'492484944'", "S10.G00.01.002,'00029'", "S10.G00.01.003,'Last name'" ]; $result = []; $previousKey = null; $index = -1; foreach ($arr as $item) { $currentKey = substr($item, 0, 10); if ($previousKey !== $currentKey) { $index++; $previousKey = $currentKey; } $result[$index][$currentKey][] = $item; } print_r($result);

preferences:
38.17 ms | 405 KiB | 5 Q