3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_numerics ($str) { preg_match_all('/\d+/', $str, $matches); return $matches[0]; } $input = 'bubur 98k'; $inputNumbers = get_numerics($input); if (count($inputNumbers) !== 1) { // lebih dari 1 angka, atau angka null print_r("formatnya yang bener dong."); } else { $tempExpense = $inputNumbers[0]; // get index of first number occurence $pos = strpos($input, (string)$tempExpense); $k = ""; if (substr($input, $pos+1,1) === 'k') { // 3k $expense = $tempExpense * 1000; } elseif (substr($input, $pos+1,1) === '.') { // 100.300 } else { // 5000 $expense = $tempExpense; } print_r($tempExpense."k \n"); print_r($expense); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J1nXW
function name:  (null)
number of ops:  50
compiled vars:  !0 = $input, !1 = $inputNumbers, !2 = $tempExpense, !3 = $pos, !4 = $k, !5 = $expense
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, 'bubur+98k'
    9     1        INIT_FCALL                                               'get_numerics'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $7      
          4        ASSIGN                                                   !1, $7
   11     5        COUNT                                            ~9      !1
          6        IS_NOT_IDENTICAL                                         ~9, 1
          7      > JMPZ                                                     ~10, ->12
   14     8    >   INIT_FCALL                                               'print_r'
          9        SEND_VAL                                                 'formatnya+yang+bener+dong.'
         10        DO_ICALL                                                 
         11      > JMP                                                      ->49
   18    12    >   FETCH_DIM_R                                      ~12     !1, 0
         13        ASSIGN                                                   !2, ~12
   21    14        INIT_FCALL                                               'strpos'
         15        SEND_VAR                                                 !0
         16        CAST                                          6  ~14     !2
         17        SEND_VAL                                                 ~14
         18        DO_ICALL                                         $15     
         19        ASSIGN                                                   !3, $15
   22    20        ASSIGN                                                   !4, ''
   24    21        INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !0
         23        ADD                                              ~18     !3, 1
         24        SEND_VAL                                                 ~18
         25        SEND_VAL                                                 1
         26        DO_ICALL                                         $19     
         27        IS_IDENTICAL                                             $19, 'k'
         28      > JMPZ                                                     ~20, ->32
   27    29    >   MUL                                              ~21     !2, 1000
         30        ASSIGN                                                   !5, ~21
         31      > JMP                                                      ->42
   29    32    >   INIT_FCALL                                               'substr'
         33        SEND_VAR                                                 !0
         34        ADD                                              ~23     !3, 1
         35        SEND_VAL                                                 ~23
         36        SEND_VAL                                                 1
         37        DO_ICALL                                         $24     
         38        IS_IDENTICAL                                             $24, '.'
         39      > JMPZ                                                     ~25, ->41
   30    40    > > JMP                                                      ->42
   37    41    >   ASSIGN                                                   !5, !2
   41    42    >   INIT_FCALL                                               'print_r'
         43        CONCAT                                           ~27     !2, 'k+%0A'
         44        SEND_VAL                                                 ~27
         45        DO_ICALL                                                 
   42    46        INIT_FCALL                                               'print_r'
         47        SEND_VAR                                                 !5
         48        DO_ICALL                                                 
   43    49    > > RETURN                                                   1

Function get_numerics:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J1nXW
function name:  get_numerics
number of ops:  9
compiled vars:  !0 = $str, !1 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%2F%5Cd%2B%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
    5     6        FETCH_DIM_R                                      ~3      !1, 0
          7      > RETURN                                                   ~3
    6     8*     > RETURN                                                   null

End of function get_numerics

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.07 ms | 1407 KiB | 22 Q