3v4l.org

run code in 300+ PHP versions simultaneously
<?php function numberToRoman(int $integer): string { static $conversions = [ 1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD', 100 => 'C', 90 => 'XC', 50 => 'L', 40 => 'XL', 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 1 => 'I' ]; $romanString = ''; foreach ($conversions as $int => $roman) { while ($integer >= $int) { $romanString .= $roman; $integer -= $int; if (!$integer) { break 2; } } } return $romanString; } echo numberToRoman(3333); echo "\n---\n"; echo numberToRoman(5000);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/96Muo
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                               'numbertoroman'
          1        SEND_VAL                                                 3333
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   33     4        ECHO                                                     '%0A---%0A'
   34     5        INIT_FCALL                                               'numbertoroman'
          6        SEND_VAL                                                 5000
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
          9      > RETURN                                                   1

Function numbertoroman:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 15
Branch analysis from position: 15
filename:       /in/96Muo
function name:  numberToRoman
number of ops:  20
compiled vars:  !0 = $integer, !1 = $conversions, !2 = $romanString, !3 = $roman, !4 = $int
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        BIND_STATIC                                              !1
   19     2        ASSIGN                                                   !2, ''
   20     3      > FE_RESET_R                                       $6      !1, ->15
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->15
          5    >   ASSIGN                                                   !4, ~7
   21     6      > JMP                                                      ->12
   22     7    >   ASSIGN_OP                                     8          !2, !3
   23     8        ASSIGN_OP                                     2          !0, !4
   24     9        BOOL_NOT                                         ~11     !0
         10      > JMPZ                                                     ~11, ->12
   25    11    > > JMP                                                      ->15
   21    12    >   IS_SMALLER_OR_EQUAL                                      !4, !0
         13      > JMPNZ                                                    ~12, ->7
   20    14    > > JMP                                                      ->4
         15    >   FE_FREE                                                  $6
   29    16        VERIFY_RETURN_TYPE                                       !2
         17      > RETURN                                                   !2
   30    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function numbertoroman

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.04 ms | 1003 KiB | 15 Q