3v4l.org

run code in 300+ PHP versions simultaneously
<?php function RomanNumeralValues() { return [ 'I'=>1, 'V'=>5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000, ]; } function ConvertRomanNumeralToArabic($input_roman){ $input_length = strlen($input_roman); if($input_length === 0) { return $result; } $roman_numerals = RomanNumeralValues(); $current_pointer = 1; $result = 0; for($i = $input_length - 1; $i > -1; $i--){ $letter = $input_roman[$i]; $letter_value = $roman_numerals[$letter]; if($letter_value === $current_pointer) { $result += $letter_value; } elseif ($letter_value < $current_pointer) { $result -= $letter_value; } else { $result += $letter_value; $current_pointer = $letter_value; } } return $result; } print ConvertRomanNumeralToArabic("LIX");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tPmQt
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               'convertromannumeraltoarabic'
          1        SEND_VAL                                                 'LIX'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function romannumeralvalues:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tPmQt
function name:  RomanNumeralValues
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   <array>
   13     1*     > RETURN                                                   null

End of function romannumeralvalues

Function convertromannumeraltoarabic:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
Branch analysis from position: 14
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 14
Branch analysis from position: 31
Branch analysis from position: 14
filename:       /in/tPmQt
function name:  ConvertRomanNumeralToArabic
number of ops:  33
compiled vars:  !0 = $input_roman, !1 = $input_length, !2 = $result, !3 = $roman_numerals, !4 = $current_pointer, !5 = $i, !6 = $letter, !7 = $letter_value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        STRLEN                                           ~8      !0
          2        ASSIGN                                                   !1, ~8
   17     3        IS_IDENTICAL                                             !1, 0
          4      > JMPZ                                                     ~10, ->6
   18     5    > > RETURN                                                   !2
   21     6    >   INIT_FCALL                                               'romannumeralvalues'
          7        DO_FCALL                                      0  $11     
          8        ASSIGN                                                   !3, $11
   23     9        ASSIGN                                                   !4, 1
   24    10        ASSIGN                                                   !2, 0
   26    11        SUB                                              ~15     !1, 1
         12        ASSIGN                                                   !5, ~15
         13      > JMP                                                      ->29
   27    14    >   FETCH_DIM_R                                      ~17     !0, !5
         15        ASSIGN                                                   !6, ~17
   28    16        FETCH_DIM_R                                      ~19     !3, !6
         17        ASSIGN                                                   !7, ~19
   29    18        IS_IDENTICAL                                             !7, !4
         19      > JMPZ                                                     ~21, ->22
   30    20    >   ASSIGN_OP                                     1          !2, !7
   29    21      > JMP                                                      ->28
   31    22    >   IS_SMALLER                                               !7, !4
         23      > JMPZ                                                     ~23, ->26
   32    24    >   ASSIGN_OP                                     2          !2, !7
   31    25      > JMP                                                      ->28
   34    26    >   ASSIGN_OP                                     1          !2, !7
   35    27        ASSIGN                                                   !4, !7
   26    28    >   PRE_DEC                                                  !5
         29    >   IS_SMALLER                                               -1, !5
         30      > JMPNZ                                                    ~28, ->14
   39    31    > > RETURN                                                   !2
   40    32*     > RETURN                                                   null

End of function convertromannumeraltoarabic

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.76 ms | 1003 KiB | 15 Q