3v4l.org

run code in 300+ PHP versions simultaneously
<?php function numToOrdinalWord($num) { $first_word = array('eth', 'First', 'Second', 'Third', 'Fourth', 'Fifth', 'Sixth', 'Seventh', 'Eighth', 'Ninth', 'Tenth', 'Eleventh', 'Twelfth', 'Thirteenth', 'Fourteenth', 'Fifteenth', 'Sixteenth', 'Seventeenth', 'Eighteenth', 'Nineteenth', 'Twentieth'); $second_word = array('', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'); if ($num <= 20) return ($num == 0) ? 'Zeroth' : $first_word[$num]; $first_num = substr($num, -1, 1); $second_num = substr($num, -2, 1); return $string = str_replace( 'y-eth', 'ieth', $second_word[$second_num] . '-' . $first_word[$first_num] ); } for($i = 0; $i < 100; $i++)echo numToOrdinalWord($i) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 2
Branch analysis from position: 10
Branch analysis from position: 2
filename:       /in/e8jRo
function name:  (null)
number of ops:  11
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->8
          2    >   INIT_FCALL                                               'numtoordinalword'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        ECHO                                                     ~3
          7        PRE_INC                                                  !0
          8    >   IS_SMALLER                                               !0, 100
          9      > JMPNZ                                                    ~5, ->2
         10    > > RETURN                                                   1

Function numtoordinalword:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e8jRo
function name:  numToOrdinalWord
number of ops:  36
compiled vars:  !0 = $num, !1 = $first_word, !2 = $second_word, !3 = $first_num, !4 = $second_num, !5 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    8     2        ASSIGN                                                   !2, <array>
   10     3        IS_SMALLER_OR_EQUAL                                      !0, 20
          4      > JMPZ                                                     ~8, ->12
          5    >   IS_EQUAL                                                 !0, 0
          6      > JMPZ                                                     ~9, ->9
          7    >   QM_ASSIGN                                        ~10     'Zeroth'
          8      > JMP                                                      ->11
          9    >   FETCH_DIM_R                                      ~11     !1, !0
         10        QM_ASSIGN                                        ~10     ~11
         11    > > RETURN                                                   ~10
   12    12    >   INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 -1
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !3, $12
   13    18        INIT_FCALL                                               'substr'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 -2
         21        SEND_VAL                                                 1
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !4, $14
   15    24        INIT_FCALL                                               'str_replace'
   16    25        SEND_VAL                                                 'y-eth'
   17    26        SEND_VAL                                                 'ieth'
   18    27        FETCH_DIM_R                                      ~16     !2, !4
         28        CONCAT                                           ~17     ~16, '-'
         29        FETCH_DIM_R                                      ~18     !1, !3
         30        CONCAT                                           ~19     ~17, ~18
         31        SEND_VAL                                                 ~19
         32        DO_ICALL                                         $20     
   15    33        ASSIGN                                           ~21     !5, $20
         34      > RETURN                                                   ~21
   20    35*     > RETURN                                                   null

End of function numtoordinalword

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.88 ms | 1403 KiB | 18 Q