3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ 0 => [ 'one' => 10, 'two' => 20, 'three' => 50, 'four' => 80, 'five' => 100], 1 => [ 'three' => 20, 'five' => 20, 'six' => 100, 'seven' => 10], 2 => [ 'one' => 30, 'three' => 30, 'five' => 10, 'eight' => 10] ]; $combined = []; foreach($input as $array) { foreach($array as $key => $value) { $combined[$key][] = $value; } } $averages = array_map(function($item) { return array_sum($item)/count($item); }, $combined); var_dump($averages);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
array(8) { ["one"]=> int(20) ["two"]=> int(20) ["three"]=> float(33.333333333333336) ["four"]=> int(80) ["five"]=> float(43.333333333333336) ["six"]=> int(100) ["seven"]=> int(10) ["eight"]=> int(10) }
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.
Output for 7.0.0 - 7.0.25, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
array(8) { ["one"]=> int(20) ["two"]=> int(20) ["three"]=> float(33.333333333333) ["four"]=> int(80) ["five"]=> float(43.333333333333) ["six"]=> int(100) ["seven"]=> int(10) ["eight"]=> int(10) }

preferences:
106.21 ms | 410 KiB | 5 Q