3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array ( 0 => array ( 'company_id' => 1, 'company_abbrev' => 'amd', 'description' => 'amd blah blah blah 1', ), 1 => array ( 'company_id' => 1, 'company_abbrev' => 'amd', 'description' => 'amd blah blah blah 2', ), 2 => array ( 'company_id' => 2, 'company_abbrev' => 'int', 'description' => 'int blah blah 1', ), 3 => array ( 'company_id' => 2, 'company_abbrev' => 'int', 'description' => 'int blah blah 2', ), ); $result = []; foreach ($array as $row) { extract($row); $result[$company_abbrev]['company_id'] = $company_id; $result[$company_abbrev]['job_descriptions'][] = $description; } var_export($result);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 'amd' => array ( 'company_id' => 1, 'job_descriptions' => array ( 0 => 'amd blah blah blah 1', 1 => 'amd blah blah blah 2', ), ), 'int' => array ( 'company_id' => 2, 'job_descriptions' => array ( 0 => 'int blah blah 1', 1 => 'int blah blah 2', ), ), )

preferences:
119.95 ms | 407 KiB | 5 Q