3v4l.org

run code in 300+ PHP versions simultaneously
<?php $births = [1997, 1997, 1997, 1998, 1999]; $deaths = [1998, 1999]; $years = []; foreach ($births as $year) { if (!isset($years[$year])) $years[$year] = 0; $years[$year]++; } foreach ($deaths as $year) { if (!isset($years[$year])) $years[$year] = 0; $years[$year]--; } ksort($years); $acc = 0; $maxYear = null; $maxYearValue = null; foreach ($years as $year => $value) { if ($acc !== 0) { $years[$year] = $value + $acc; } $acc = $acc + $value; if ($acc > $maxYearValue) { $maxYear = $year; $maxYearValue = $acc; } } var_dump($years, $maxYear, $maxYearValue);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 21
Branch analysis from position: 24
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 46
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 46
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 45
Branch analysis from position: 39
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 24
Branch analysis from position: 13
filename:       /in/Gi1Zi
function name:  (null)
number of ops:  53
compiled vars:  !0 = $births, !1 = $deaths, !2 = $years, !3 = $year, !4 = $acc, !5 = $maxYear, !6 = $maxYearValue, !7 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    8     3      > FE_RESET_R                                       $11     !0, ->13
          4    > > FE_FETCH_R                                               $11, !3, ->13
    9     5    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !2, !3
          6        BOOL_NOT                                         ~13     ~12
          7      > JMPZ                                                     ~13, ->10
          8    >   ASSIGN_DIM                                               !2, !3
          9        OP_DATA                                                  0
   10    10    >   FETCH_DIM_RW                                     $15     !2, !3
         11        PRE_INC                                                  $15
    8    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $11
   12    14      > FE_RESET_R                                       $17     !1, ->24
         15    > > FE_FETCH_R                                               $17, !3, ->24
   13    16    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !2, !3
         17        BOOL_NOT                                         ~19     ~18
         18      > JMPZ                                                     ~19, ->21
         19    >   ASSIGN_DIM                                               !2, !3
         20        OP_DATA                                                  0
   14    21    >   FETCH_DIM_RW                                     $21     !2, !3
         22        PRE_DEC                                                  $21
   12    23      > JMP                                                      ->15
         24    >   FE_FREE                                                  $17
   17    25        INIT_FCALL                                               'ksort'
         26        SEND_REF                                                 !2
         27        DO_ICALL                                                 
   18    28        ASSIGN                                                   !4, 0
   19    29        ASSIGN                                                   !5, null
   20    30        ASSIGN                                                   !6, null
   21    31      > FE_RESET_R                                       $27     !2, ->46
         32    > > FE_FETCH_R                                       ~28     $27, !7, ->46
         33    >   ASSIGN                                                   !3, ~28
   22    34        IS_NOT_IDENTICAL                                         !4, 0
         35      > JMPZ                                                     ~30, ->39
   23    36    >   ADD                                              ~32     !7, !4
         37        ASSIGN_DIM                                               !2, !3
         38        OP_DATA                                                  ~32
   25    39    >   ADD                                              ~33     !4, !7
         40        ASSIGN                                                   !4, ~33
   26    41        IS_SMALLER                                               !6, !4
         42      > JMPZ                                                     ~35, ->45
   27    43    >   ASSIGN                                                   !5, !3
   28    44        ASSIGN                                                   !6, !4
   21    45    > > JMP                                                      ->32
         46    >   FE_FREE                                                  $27
   31    47        INIT_FCALL                                               'var_dump'
         48        SEND_VAR                                                 !2
         49        SEND_VAR                                                 !5
         50        SEND_VAR                                                 !6
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.06 ms | 1400 KiB | 17 Q