3v4l.org

run code in 300+ PHP versions simultaneously
<?php // user input of years - note it must be numeric $ar = array(1944, 1674, 3021); // find max year of the input for 'dynamic' approach // note the unpacking of the array is not needed I do not think // but does work - check performance $maxCentury = max(...$ar); // round max century to -3 (closest 1000) $roundedCentury = round($maxCentury, -3); foreach($ar as $year): foreach(range(0, $maxCentury, 1000) as $century): if(round($year, -3) == $century): ?> <li> <?= $century; ?> <ul> <?= $year; ?> </ul> </li> <?php endif; endforeach; endforeach;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 34
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 34
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 32
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 32
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/jdLaP
function name:  (null)
number of ops:  36
compiled vars:  !0 = $ar, !1 = $maxCentury, !2 = $roundedCentury, !3 = $year, !4 = $century
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    9     1        INIT_FCALL                                               'max'
          2        SEND_UNPACK                                              !0
          3        CHECK_UNDEF_ARGS                                         
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !1, $6
   12     6        INIT_FCALL                                               'round'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 -3
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !2, $8
   14    11      > FE_RESET_R                                       $10     !0, ->34
         12    > > FE_FETCH_R                                               $10, !3, ->34
   15    13    >   INIT_FCALL                                               'range'
         14        SEND_VAL                                                 0
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 1000
         17        DO_ICALL                                         $11     
         18      > FE_RESET_R                                       $12     $11, ->32
         19    > > FE_FETCH_R                                               $12, !4, ->32
   16    20    >   INIT_FCALL                                               'round'
         21        SEND_VAR                                                 !3
         22        SEND_VAL                                                 -3
         23        DO_ICALL                                         $13     
         24        IS_EQUAL                                                 !4, $13
         25      > JMPZ                                                     ~14, ->31
   17    26    >   ECHO                                                     '++++++++++++%3Cli%3E+'
         27        ECHO                                                     !4
   18    28        ECHO                                                     '++++++++++++++++%3Cul%3E+'
         29        ECHO                                                     !3
         30        ECHO                                                     '+%3C%2Ful%3E%0A++++++++++++%3C%2Fli%3E%0A++++++++'
   15    31    > > JMP                                                      ->19
         32    >   FE_FREE                                                  $12
   14    33      > JMP                                                      ->12
         34    >   FE_FREE                                                  $10
   22    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.89 ms | 1400 KiB | 19 Q