3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cms = Array ( '0' => Array ( 'id' => 31, 'day_date' => '2020-01-30 00:00:00', 'new_visitors' => 459 ), '1' => Array ( 'id' => 32, 'day_date' => '2020-01-31 00:00:00', 'new_visitors' => 338 ), '2' => Array ( 'id' => 33, 'day_date' => '2020-02-01 00:00:00', 'new_visitors' => 242 ), '3' => Array ( 'id' => 34, 'day_date' => '2020-02-02 00:00:00', 'new_visitors' => 219 ) ); $tmp_array = array(); foreach ($cms as $key => $val) { $cDate = date('Ym', strtotime($val['day_date'])); if (array_key_exists($cDate, array_keys($tmp_array))) { $tmp_array[$cDate]['new_visitors'] += $val['new_visitors']; } else { $tmp_array[$cDate]['new_visitors'] = $val['new_visitors']; } $tmp_array[$cDate]['ids'][] = $val['id']; } print_r($tmp_array);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [202001] => Array ( [new_visitors] => 338 [ids] => Array ( [0] => 31 [1] => 32 ) ) [202002] => Array ( [new_visitors] => 219 [ids] => Array ( [0] => 33 [1] => 34 ) ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [202001] => Array ( [new_visitors] => 338 [ids] => Array ( [0] => 31 [1] => 32 ) ) [202002] => Array ( [new_visitors] => 219 [ids] => Array ( [0] => 33 [1] => 34 ) ) )

preferences:
177.22 ms | 403 KiB | 179 Q