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) { echo "\tcheck $roman\n"; while ($integer >= $int) { echo "\tsubtract $int\n"; $romanString .= $roman; if (!($integer -= $int)) { break 2; } } } return $romanString; } echo numberToRoman(3333); echo "\n---\n"; echo numberToRoman(5000); echo "\n======\n"; function numberToRomanRepresentation($number) { $map = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); $returnValue = ''; while ($number > 0) { foreach ($map as $roman => $int) { echo "\tcheck $roman\n"; if($number >= $int) { echo "\tsubtract $int\n"; $number -= $int; $returnValue .= $roman; break; } } } return $returnValue; } echo numberToRomanRepresentation(3333); echo "\n---\n"; echo numberToRomanRepresentation(5000);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jiVR5
function name:  (null)
number of ops:  20
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_FCALL                                               'numbertoroman'
          1        SEND_VAL                                                 3333
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   34     4        ECHO                                                     '%0A---%0A'
   35     5        INIT_FCALL                                               'numbertoroman'
          6        SEND_VAL                                                 5000
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
   37     9        ECHO                                                     '%0A%3D%3D%3D%3D%3D%3D%0A'
   56    10        INIT_FCALL                                               'numbertoromanrepresentation'
         11        SEND_VAL                                                 3333
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
   57    14        ECHO                                                     '%0A---%0A'
   58    15        INIT_FCALL                                               'numbertoromanrepresentation'
         16        SEND_VAL                                                 5000
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
         19      > RETURN                                                   1

Function numbertoroman:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 11
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 23
Branch analysis from position: 23
filename:       /in/jiVR5
function name:  numberToRoman
number of ops:  28
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, ->23
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->23
          5    >   ASSIGN                                                   !4, ~7
   21     6        ROPE_INIT                                     3  ~10     '%09check+'
          7        ROPE_ADD                                      1  ~10     ~10, !3
          8        ROPE_END                                      2  ~9      ~10, '%0A'
          9        ECHO                                                     ~9
   22    10      > JMP                                                      ->20
   23    11    >   ROPE_INIT                                     3  ~13     '%09subtract+'
         12        ROPE_ADD                                      1  ~13     ~13, !4
         13        ROPE_END                                      2  ~12     ~13, '%0A'
         14        ECHO                                                     ~12
   24    15        ASSIGN_OP                                     8          !2, !3
   25    16        ASSIGN_OP                                     2  ~16     !0, !4
         17        BOOL_NOT                                         ~17     ~16
         18      > JMPZ                                                     ~17, ->20
   26    19    > > JMP                                                      ->23
   22    20    >   IS_SMALLER_OR_EQUAL                                      !4, !0
         21      > JMPNZ                                                    ~18, ->11
   20    22    > > JMP                                                      ->4
         23    >   FE_FREE                                                  $6
   30    24        VERIFY_RETURN_TYPE                                       !2
         25      > RETURN                                                   !2
   31    26*       VERIFY_RETURN_TYPE                                       
         27*     > RETURN                                                   null

End of function numbertoroman

Function numbertoromanrepresentation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 4
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 21
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 4
Branch analysis from position: 24
Branch analysis from position: 4
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 21
Branch analysis from position: 21
filename:       /in/jiVR5
function name:  numberToRomanRepresentation
number of ops:  26
compiled vars:  !0 = $number, !1 = $map, !2 = $returnValue, !3 = $int, !4 = $roman
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        ASSIGN                                                   !1, <array>
   41     2        ASSIGN                                                   !2, ''
   42     3      > JMP                                                      ->22
   43     4    > > FE_RESET_R                                       $7      !1, ->21
          5    > > FE_FETCH_R                                       ~8      $7, !3, ->21
          6    >   ASSIGN                                                   !4, ~8
   44     7        ROPE_INIT                                     3  ~11     '%09check+'
          8        ROPE_ADD                                      1  ~11     ~11, !4
          9        ROPE_END                                      2  ~10     ~11, '%0A'
         10        ECHO                                                     ~10
   45    11        IS_SMALLER_OR_EQUAL                                      !3, !0
         12      > JMPZ                                                     ~13, ->20
   46    13    >   ROPE_INIT                                     3  ~15     '%09subtract+'
         14        ROPE_ADD                                      1  ~15     ~15, !3
         15        ROPE_END                                      2  ~14     ~15, '%0A'
         16        ECHO                                                     ~14
   47    17        ASSIGN_OP                                     2          !0, !3
   48    18        ASSIGN_OP                                     8          !2, !4
   49    19      > JMP                                                      ->21
   43    20    > > JMP                                                      ->5
         21    >   FE_FREE                                                  $7
   42    22    >   IS_SMALLER                                               0, !0
         23      > JMPNZ                                                    ~19, ->4
   53    24    > > RETURN                                                   !2
   54    25*     > RETURN                                                   null

End of function numbertoromanrepresentation

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.93 ms | 1011 KiB | 17 Q