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] ] ] ]; foreach ($array as &$lv1) { foreach ($lv1 as &$lv2) { foreach ($lv2 as &$lv3) { sort($lv3); // order values ASC $count = sizeof($lv3); // count number of values $index = floor($count / 2); // get middle index or upper of middle two if (!$count) { // count is zero $lv3 = 0; } elseif ($count & 1) { // count is odd $lv3 = (int)$lv3[$index]; // single median } else { // count is even $lv3 = ((int)$lv3[$index-1] + (int)$lv3[$index]) / 2; // dual median } } } } var_export($array);
Output for git.master, git.master_jit, rfc.property-hooks
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, ), ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.5 ms | 406 KiB | 5 Q