3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['date' => '2017-08-22', 'AAA' => 1231], ['date' => '2017-08-21', 'AAA' => 1172], ['date' => '2017-08-20', 'AAA' => 1125], ['date' => '2017-08-21', 'BBB' => 251], ['date' => '2017-08-20', 'BBB' => 21773], ['date' => '2017-08-22', 'CCC' => 3750], ['date' => '2017-08-20', 'CCC' => 321750], ]; foreach ($array as $row) { $date = $row['date']; unset($row['date']); $result[$date] = array_merge($result[$date] ?? [], $row); } var_export($result);
Output for 7.0.0, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( '2017-08-22' => array ( 'AAA' => 1231, 'CCC' => 3750, ), '2017-08-21' => array ( 'AAA' => 1172, 'BBB' => 251, ), '2017-08-20' => array ( 'AAA' => 1125, 'BBB' => 21773, 'CCC' => 321750, ), )
Output for 5.4.24, 5.6.13 - 5.6.40
Parse error: syntax error, unexpected '?' in /in/XVBZm on line 16
Process exited with code 255.
Output for 4.3.0
Parse error: parse error, unexpected '[' in /in/XVBZm on line 3
Process exited with code 255.

preferences:
174.65 ms | 408 KiB | 5 Q