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) { $acc = $acc + $value; if ($acc > $maxYearValue) { $maxYear = $year; $maxYearValue = $acc; } } var_dump($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 = 41
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 41
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 40
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
Branch analysis from position: 24
Branch analysis from position: 13
filename:       /in/X939S
function name:  (null)
number of ops:  47
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, ->41
         32    > > FE_FETCH_R                                       ~28     $27, !7, ->41
         33    >   ASSIGN                                                   !3, ~28
   22    34        ADD                                              ~30     !4, !7
         35        ASSIGN                                                   !4, ~30
   23    36        IS_SMALLER                                               !6, !4
         37      > JMPZ                                                     ~32, ->40
   24    38    >   ASSIGN                                                   !5, !3
   25    39        ASSIGN                                                   !6, !4
   21    40    > > JMP                                                      ->32
         41    >   FE_FREE                                                  $27
   28    42        INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !5
         44        SEND_VAR                                                 !6
         45        DO_ICALL                                                 
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.82 ms | 1400 KiB | 17 Q