3v4l.org

run code in 300+ PHP versions simultaneously
<?php function displaywords($number){ $words = array('0' => '', '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten', '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen', '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen', '18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty', '30' => 'thirty', '40' => 'forty', '50' => 'fifty', '60' => 'sixty', '70' => 'seventy', '80' => 'eighty', '90' => 'ninety'); $digits = array('', '', 'hundred', 'thousand', 'lakh', 'crore'); $number = explode(".", $number); $result = array("",""); $j =0; foreach($number as $val){ // loop each part of number, right and left of dot for($i=0;$i<strlen($val);$i++){ // look at each part of the number separately [1] [5] [4] [2] and [5] [8] $numberpart = str_pad($val[$i], strlen($val)-$i, "0", STR_PAD_RIGHT); // make 1 => 1000, 5 => 500, 4 => 40 etc. if($numberpart <= 20){ $numberpart = 1*substr($val, $i,2); $i++; $result[$j] .= $words[$numberpart] ." "; }else{ //echo $numberpart . "<br>\n"; //debug if($numberpart > 90){ // more than 90 and it needs a $digit. $result[$j] .= $words[$val[$i]] . " " . $digits[strlen($numberpart)-1] . " "; }else if($numberpart != 0){ // don't print zero $result[$j] .= $words[str_pad($val[$i], strlen($val)-$i, "0", STR_PAD_RIGHT)] ." "; } } } $j++; } if(trim($result[0]) != "") echo $result[0] . "Rupees "; if($result[1] != "") echo $result[1] . "Paise"; echo " Only"; } $ins=1516.00; echo displaywords($ins);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rFvbJ
function name:  (null)
number of ops:  6
compiled vars:  !0 = $ins
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, 1516
   47     1        INIT_FCALL                                               'displaywords'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function displaywords:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 73
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 73
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 14
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 14
Branch analysis from position: 71
Branch analysis from position: 14
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 52
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 67
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 71, Position 2 = 14
Branch analysis from position: 71
Branch analysis from position: 14
Branch analysis from position: 67
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 83
Branch analysis from position: 80
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 89
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
Branch analysis from position: 83
Branch analysis from position: 73
filename:       /in/rFvbJ
function name:  displaywords
number of ops:  91
compiled vars:  !0 = $number, !1 = $words, !2 = $digits, !3 = $result, !4 = $j, !5 = $val, !6 = $i, !7 = $numberpart
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, <array>
   16     3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '.'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !0, $10
   17     8        ASSIGN                                                   !3, <array>
   18     9        ASSIGN                                                   !4, 0
   19    10      > FE_RESET_R                                       $14     !0, ->73
         11    > > FE_FETCH_R                                               $14, !5, ->73
   21    12    >   ASSIGN                                                   !6, 0
         13      > JMP                                                      ->68
   24    14    >   INIT_FCALL                                               'str_pad'
         15        FETCH_DIM_R                                      ~16     !5, !6
         16        SEND_VAL                                                 ~16
         17        STRLEN                                           ~17     !5
         18        SUB                                              ~18     ~17, !6
         19        SEND_VAL                                                 ~18
         20        SEND_VAL                                                 '0'
         21        SEND_VAL                                                 1
         22        DO_ICALL                                         $19     
         23        ASSIGN                                                   !7, $19
   25    24        IS_SMALLER_OR_EQUAL                                      !7, 20
         25      > JMPZ                                                     ~21, ->39
   26    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !5
         28        SEND_VAR                                                 !6
         29        SEND_VAL                                                 2
         30        DO_ICALL                                         $22     
         31        MUL                                              ~23     $22, 1
         32        ASSIGN                                                   !7, ~23
   27    33        PRE_INC                                                  !6
   28    34        FETCH_DIM_R                                      ~27     !1, !7
         35        CONCAT                                           ~28     ~27, '+'
         36        ASSIGN_DIM_OP                .=               8          !3, !4
         37        OP_DATA                                                  ~28
         38      > JMP                                                      ->67
   31    39    >   IS_SMALLER                                               90, !7
         40      > JMPZ                                                     ~29, ->52
   32    41    >   FETCH_DIM_R                                      ~31     !5, !6
         42        FETCH_DIM_R                                      ~32     !1, ~31
         43        CONCAT                                           ~33     ~32, '+'
         44        STRLEN                                           ~34     !7
         45        SUB                                              ~35     ~34, 1
         46        FETCH_DIM_R                                      ~36     !2, ~35
         47        CONCAT                                           ~37     ~33, ~36
         48        CONCAT                                           ~38     ~37, '+'
         49        ASSIGN_DIM_OP                .=               8          !3, !4
         50        OP_DATA                                                  ~38
         51      > JMP                                                      ->67
   33    52    >   IS_NOT_EQUAL                                             !7, 0
         53      > JMPZ                                                     ~39, ->67
   34    54    >   INIT_FCALL                                               'str_pad'
         55        FETCH_DIM_R                                      ~41     !5, !6
         56        SEND_VAL                                                 ~41
         57        STRLEN                                           ~42     !5
         58        SUB                                              ~43     ~42, !6
         59        SEND_VAL                                                 ~43
         60        SEND_VAL                                                 '0'
         61        SEND_VAL                                                 1
         62        DO_ICALL                                         $44     
         63        FETCH_DIM_R                                      ~45     !1, $44
         64        CONCAT                                           ~46     ~45, '+'
         65        ASSIGN_DIM_OP                .=               8          !3, !4
         66        OP_DATA                                                  ~46
   21    67    >   PRE_INC                                                  !6
         68    >   STRLEN                                           ~48     !5
         69        IS_SMALLER                                               !6, ~48
         70      > JMPNZ                                                    ~49, ->14
   38    71    >   PRE_INC                                                  !4
   19    72      > JMP                                                      ->11
         73    >   FE_FREE                                                  $14
   40    74        INIT_FCALL                                               'trim'
         75        FETCH_DIM_R                                      ~51     !3, 0
         76        SEND_VAL                                                 ~51
         77        DO_ICALL                                         $52     
         78        IS_NOT_EQUAL                                             $52, ''
         79      > JMPZ                                                     ~53, ->83
         80    >   FETCH_DIM_R                                      ~54     !3, 0
         81        CONCAT                                           ~55     ~54, 'Rupees+'
         82        ECHO                                                     ~55
   41    83    >   FETCH_DIM_R                                      ~56     !3, 1
         84        IS_NOT_EQUAL                                             ~56, ''
         85      > JMPZ                                                     ~57, ->89
         86    >   FETCH_DIM_R                                      ~58     !3, 1
         87        CONCAT                                           ~59     ~58, 'Paise'
         88        ECHO                                                     ~59
   42    89    >   ECHO                                                     '+Only'
   43    90      > RETURN                                                   null

End of function displaywords

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.54 ms | 1411 KiB | 22 Q