3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parsePrice(string $price): int { // 0 - рубли, 1 - копейки $price = trim(str_replace(['руб.', ' ',], ['', ''], $price)); $price = str_replace(',', '.', $price); $priceExp = []; $amount = 0; if (str_contains($price, '.')) { $priceExp = explode('.', $price); $amount = (int) str_pad(substr($priceExp[1], 0, 2), 2, '0'); } return (int) ($priceExp[0] ?? $price) * 100 + $amount; } print parsePrice('Нет в наличии');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/usNIp
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'parseprice'
          1        SEND_VAL                                                 '%D0%9D%D0%B5%D1%82+%D0%B2+%D0%BD%D0%B0%D0%BB%D0%B8%D1%87%D0%B8%D0%B8'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function parseprice:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 41
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/usNIp
function name:  parsePrice
number of ops:  51
compiled vars:  !0 = $price, !1 = $priceExp, !2 = $amount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'trim'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 <array>
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !0, $4
    9    10        INIT_FCALL                                               'str_replace'
         11        SEND_VAL                                                 '%2C'
         12        SEND_VAL                                                 '.'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $6      
         15        ASSIGN                                                   !0, $6
   11    16        ASSIGN                                                   !1, <array>
   12    17        ASSIGN                                                   !2, 0
   13    18        INIT_FCALL                                               'str_contains'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 '.'
         21        DO_ICALL                                         $10     
         22      > JMPZ                                                     $10, ->41
   14    23    >   INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '.'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $11     
         27        ASSIGN                                                   !1, $11
   15    28        INIT_FCALL                                               'str_pad'
         29        INIT_FCALL                                               'substr'
         30        FETCH_DIM_R                                      ~13     !1, 1
         31        SEND_VAL                                                 ~13
         32        SEND_VAL                                                 0
         33        SEND_VAL                                                 2
         34        DO_ICALL                                         $14     
         35        SEND_VAR                                                 $14
         36        SEND_VAL                                                 2
         37        SEND_VAL                                                 '0'
         38        DO_ICALL                                         $15     
         39        CAST                                          4  ~16     $15
         40        ASSIGN                                                   !2, ~16
   18    41    >   FETCH_DIM_IS                                     ~18     !1, 0
         42        COALESCE                                         ~19     ~18
         43        QM_ASSIGN                                        ~19     !0
         44        CAST                                          4  ~20     ~19
         45        MUL                                              ~21     ~20, 100
         46        ADD                                              ~22     ~21, !2
         47        VERIFY_RETURN_TYPE                                       ~22
         48      > RETURN                                                   ~22
   19    49*       VERIFY_RETURN_TYPE                                       
         50*     > RETURN                                                   null

End of function parseprice

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.24 ms | 1018 KiB | 20 Q