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 $k1 => $lv1) { foreach ($lv1 as $k2 => $lv2) { foreach ($lv2 as $k3 => $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 $medians[$k1][$k2][$k3] = 0; } elseif ($count & 1) { // count is odd $medians[$k1][$k2][$k3] = (int)$lv3[$index]; // single median } else { // count is even $medians[$k1][$k2][$k3] = ((int)$lv3[$index-1] + (int)$lv3[$index]) / 2; // dual median } } } } var_export($medians);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 52
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 52
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 50
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 50
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 48
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 48
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 27
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 48
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 50
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/vL5D4
function name:  (null)
number of ops:  57
compiled vars:  !0 = $array, !1 = $lv1, !2 = $k1, !3 = $lv2, !4 = $k2, !5 = $lv3, !6 = $k3, !7 = $count, !8 = $index, !9 = $medians
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_R                                       $11     !0, ->52
          2    > > FE_FETCH_R                                       ~12     $11, !1, ->52
          3    >   ASSIGN                                                   !2, ~12
   27     4      > FE_RESET_R                                       $14     !1, ->50
          5    > > FE_FETCH_R                                       ~15     $14, !3, ->50
          6    >   ASSIGN                                                   !4, ~15
   28     7      > FE_RESET_R                                       $17     !3, ->48
          8    > > FE_FETCH_R                                       ~18     $17, !5, ->48
          9    >   ASSIGN                                                   !6, ~18
   29    10        INIT_FCALL                                               'sort'
         11        SEND_REF                                                 !5
         12        DO_ICALL                                                 
   30    13        COUNT                                            ~21     !5
         14        ASSIGN                                                   !7, ~21
   31    15        INIT_FCALL                                               'floor'
         16        DIV                                              ~23     !7, 2
         17        SEND_VAL                                                 ~23
         18        DO_ICALL                                         $24     
         19        ASSIGN                                                   !8, $24
   32    20        BOOL_NOT                                         ~26     !7
         21      > JMPZ                                                     ~26, ->27
   33    22    >   FETCH_DIM_W                                      $27     !9, !2
         23        FETCH_DIM_W                                      $28     $27, !4
         24        ASSIGN_DIM                                               $28, !6
         25        OP_DATA                                                  0
   32    26      > JMP                                                      ->47
   34    27    >   BW_AND                                           ~30     !7, 1
         28      > JMPZ                                                     ~30, ->36
   35    29    >   FETCH_DIM_R                                      ~34     !5, !8
         30        CAST                                          4  ~35     ~34
         31        FETCH_DIM_W                                      $31     !9, !2
         32        FETCH_DIM_W                                      $32     $31, !4
         33        ASSIGN_DIM                                               $32, !6
         34        OP_DATA                                                  ~35
   34    35      > JMP                                                      ->47
   37    36    >   SUB                                              ~39     !8, 1
         37        FETCH_DIM_R                                      ~40     !5, ~39
         38        CAST                                          4  ~41     ~40
         39        FETCH_DIM_R                                      ~42     !5, !8
         40        CAST                                          4  ~43     ~42
         41        ADD                                              ~44     ~41, ~43
         42        DIV                                              ~45     ~44, 2
         43        FETCH_DIM_W                                      $36     !9, !2
         44        FETCH_DIM_W                                      $37     $36, !4
         45        ASSIGN_DIM                                               $37, !6
         46        OP_DATA                                                  ~45
   28    47    > > JMP                                                      ->8
         48    >   FE_FREE                                                  $17
   27    49      > JMP                                                      ->5
         50    >   FE_FREE                                                  $14
   26    51      > JMP                                                      ->2
         52    >   FE_FREE                                                  $11
   42    53        INIT_FCALL                                               'var_export'
         54        SEND_VAR                                                 !9
         55        DO_ICALL                                                 
         56      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.47 ms | 1009 KiB | 16 Q