3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = Array ( 0 => Array ( 'date' => '2017-08-22', 'AAA' => '1231', ), 1 => Array ( 'date' => '2017-08-21', 'AAA' => '1172', ), 2 => Array ( 'date' => '2017-08-20', 'AAA' => '1125' ), 3 => Array ( 'date' => '2017-08-21', 'BBB' => '251' ), 4 => Array ( 'date' => '2017-08-20', 'BBB' => '21773', ), 5 => Array ( 'date' => '2017-08-22', 'CCC' => '3750' ), 6 => Array ( 'date' => '2017-08-20', 'CCC' => '321750' ) ); echo '<pre>'; $array1 = array('AAA' => null, 'BBB' => null, 'CCC' => null); $array2 = array(); array_walk($array, function ($v) use (&$array2, $array1) { $a = $v['date']; if (!isset($array2[$a])) { $array2[$a] = $array1; } unset($v['date']); $array2[$a] = array_merge($array2[$a], $v); }); print_r($array2);
Output for 5.6.38 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9, 8.0.0alpha1 - beta1
<pre>Array ( [2017-08-22] => Array ( [AAA] => 1231 [BBB] => [CCC] => 3750 ) [2017-08-21] => Array ( [AAA] => 1172 [BBB] => 251 [CCC] => ) [2017-08-20] => Array ( [AAA] => 1125 [BBB] => 21773 [CCC] => 321750 ) )