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 &$dateSet) { foreach ($dateSet as &$dcSet) { foreach ($dcSet as &$set) { if (!$set) { $set = 0; continue; } sort($set); $count = count($set); $mid = intdiv($count, 2); if ($count & 1) { $set = $set[$mid]; continue; } $set = ((int)$set[$mid - 1] + (int)$set[$mid]) / 2; } } } var_export($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 39
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 39
Branch analysis from position: 3
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 37
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 125) Position 1 = 6, Position 2 = 35
Branch analysis from position: 6
2 jumps found. (Code = 126) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 35
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 37
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/L7DXo
function name:  (null)
number of ops:  44
compiled vars:  !0 = $array, !1 = $dateSet, !2 = $dcSet, !3 = $set, !4 = $count, !5 = $mid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_RW                                      $7      !0, ->39
          2    > > FE_FETCH_RW                                              $7, !1, ->39
   27     3    > > FE_RESET_RW                                      $8      !1, ->37
          4    > > FE_FETCH_RW                                              $8, !2, ->37
   28     5    > > FE_RESET_RW                                      $9      !2, ->35
          6    > > FE_FETCH_RW                                              $9, !3, ->35
   29     7    >   BOOL_NOT                                         ~10     !3
          8      > JMPZ                                                     ~10, ->11
   30     9    >   ASSIGN                                                   !3, 0
   31    10      > JMP                                                      ->6
   33    11    >   INIT_FCALL                                               'sort'
         12        SEND_REF                                                 !3
         13        DO_ICALL                                                 
   34    14        COUNT                                            ~13     !3
         15        ASSIGN                                                   !4, ~13
   35    16        INIT_FCALL                                               'intdiv'
         17        SEND_VAR                                                 !4
         18        SEND_VAL                                                 2
         19        DO_ICALL                                         $15     
         20        ASSIGN                                                   !5, $15
   36    21        BW_AND                                           ~17     !4, 1
         22      > JMPZ                                                     ~17, ->26
   37    23    >   FETCH_DIM_R                                      ~18     !3, !5
         24        ASSIGN                                                   !3, ~18
   38    25      > JMP                                                      ->6
   40    26    >   SUB                                              ~20     !5, 1
         27        FETCH_DIM_R                                      ~21     !3, ~20
         28        CAST                                          4  ~22     ~21
         29        FETCH_DIM_R                                      ~23     !3, !5
         30        CAST                                          4  ~24     ~23
         31        ADD                                              ~25     ~22, ~24
         32        DIV                                              ~26     ~25, 2
         33        ASSIGN                                                   !3, ~26
   28    34      > JMP                                                      ->6
         35    >   FE_FREE                                                  $9
   27    36      > JMP                                                      ->4
         37    >   FE_FREE                                                  $8
   26    38      > JMP                                                      ->2
         39    >   FE_FREE                                                  $7
   44    40        INIT_FCALL                                               'var_export'
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.61 ms | 1017 KiB | 16 Q