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] ] ] ]; array_walk( $array, fn(&$dateSet) => array_walk( $dateSet, fn(&$dcSet) => array_walk( $dcSet, function (&$set) { if (!$set) { $set = 0; return; } sort($set); $count = count($set); $mid = intdiv($count, 2); if ($count & 1) { $set = $set[$mid]; return; } $set = ((int)$set[$mid - 1] + (int)$set[$mid]) / 2; } ) ) ); var_export($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
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:
82.1 ms | 407 KiB | 5 Q