3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ '2017-05-01' => [ 'DC' => [ 'IT' => [90, 0], 'DE' => [18, 315, 40, '', 69, 211], 'Other' => [107, 46, '', '', 27, 22] ] ], '2017-05-02' => [ 'DC' => [ 'IT' => [70, 40, 55], 'DE' => ['', 31, 4, '', 9], 'Other' => [1107, 12, 0, 20, 1, 11, 21] ] ], 'fringe case' => [ 'DC' => [ 'IT' => [], 'DE' => ['', '', '', 99], 'Other' => ['', 99] ] ] ]; var_export( array_map( fn($dateSet) => array_map( fn($dcSet) => array_map( function ($set) { if (!$set) { return 0; } sort($set); $count = count($set); $mid = intdiv($count, 2); if ($count & 1) { return $set[$mid]; } return ((int)$set[$mid - 1] + (int)$set[$mid]) / 2; }, $dcSet ), $dateSet ), $array ) );
Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
array ( '2017-05-01' => array ( 'DC' => array ( 'IT' => 45, 'DE' => 54.5, 'Other' => 24.5, ), ), '2017-05-02' => array ( 'DC' => array ( 'IT' => 55, 'DE' => 4, 'Other' => 12, ), ), 'fringe case' => array ( 'DC' => array ( 'IT' => 0, 'DE' => 0, 'Other' => 49.5, ), ), )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
80.02 ms | 407 KiB | 5 Q