3v4l.org

run code in 300+ PHP versions simultaneously
<?php $digits = 10; foreach([7887.0000000000000000, 8667887.0000000000000000, 0.0786451, 1.0786451] as $lastPrice) { $price = number_format($lastPrice, 16, '.', ''); $price = ltrim($price, '-'); $price = rtrim($price, '0'); list($d, $s) = explode('.', $price); var_dump($price); var_dump([$d, $s]); if ($d !== '0') { $round = $digits - strlen($d); } else { $round = $digits + strlen($s) - strlen(ltrim($s, '0')); } var_dump($round); } return; foreach ([7887.0000000000000000, 0.0786451] as $price) { $maxDigits = 5; $log = floor(round(log($price) / M_LN10, 10)); var_dump($log); var_dump((10 ** ($maxDigits - $log))); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 56
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 56
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/DALWi
function name:  (null)
number of ops:  84
compiled vars:  !0 = $digits, !1 = $lastPrice, !2 = $price, !3 = $d, !4 = $s, !5 = $round, !6 = $maxDigits, !7 = $log
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 10
    3     1      > FE_RESET_R                                       $9      <array>, ->56
          2    > > FE_FETCH_R                                               $9, !1, ->56
    4     3    >   INIT_FCALL                                               'number_format'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 16
          6        SEND_VAL                                                 '.'
          7        SEND_VAL                                                 ''
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !2, $10
    5    10        INIT_FCALL                                               'ltrim'
         11        SEND_VAR                                                 !2
         12        SEND_VAL                                                 '-'
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !2, $12
    6    15        INIT_FCALL                                               'rtrim'
         16        SEND_VAR                                                 !2
         17        SEND_VAL                                                 '0'
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !2, $14
    8    20        INIT_FCALL                                               'explode'
         21        SEND_VAL                                                 '.'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $16     
         24        FETCH_LIST_R                                     $17     $16, 0
         25        ASSIGN                                                   !3, $17
         26        FETCH_LIST_R                                     $19     $16, 1
         27        ASSIGN                                                   !4, $19
         28        FREE                                                     $16
    9    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !2
         31        DO_ICALL                                                 
   10    32        INIT_FCALL                                               'var_dump'
         33        INIT_ARRAY                                       ~22     !3
         34        ADD_ARRAY_ELEMENT                                ~22     !4
         35        SEND_VAL                                                 ~22
         36        DO_ICALL                                                 
   12    37        IS_NOT_IDENTICAL                                         !3, '0'
         38      > JMPZ                                                     ~24, ->43
   13    39    >   STRLEN                                           ~25     !3
         40        SUB                                              ~26     !0, ~25
         41        ASSIGN                                                   !5, ~26
         42      > JMP                                                      ->52
   15    43    >   STRLEN                                           ~28     !4
         44        ADD                                              ~29     !0, ~28
         45        INIT_FCALL                                               'ltrim'
         46        SEND_VAR                                                 !4
         47        SEND_VAL                                                 '0'
         48        DO_ICALL                                         $30     
         49        STRLEN                                           ~31     $30
         50        SUB                                              ~32     ~29, ~31
         51        ASSIGN                                                   !5, ~32
   17    52    >   INIT_FCALL                                               'var_dump'
         53        SEND_VAR                                                 !5
         54        DO_ICALL                                                 
    3    55      > JMP                                                      ->2
         56    >   FE_FREE                                                  $9
   20    57      > RETURN                                                   null
   21    58*       FE_RESET_R                                       $35     <array>, ->82
         59*       FE_FETCH_R                                               $35, !2, ->82
   22    60*       ASSIGN                                                   !6, 5
   23    61*       INIT_FCALL                                               'floor'
         62*       INIT_FCALL                                               'round'
         63*       INIT_FCALL                                               'log'
         64*       SEND_VAR                                                 !2
         65*       DO_ICALL                                         $37     
         66*       DIV                                              ~38     $37, 2.30259
         67*       SEND_VAL                                                 ~38
         68*       SEND_VAL                                                 10
         69*       DO_ICALL                                         $39     
         70*       SEND_VAR                                                 $39
         71*       DO_ICALL                                         $40     
         72*       ASSIGN                                                   !7, $40
   24    73*       INIT_FCALL                                               'var_dump'
         74*       SEND_VAR                                                 !7
         75*       DO_ICALL                                                 
   25    76*       INIT_FCALL                                               'var_dump'
         77*       SUB                                              ~43     !6, !7
         78*       POW                                              ~44     10, ~43
         79*       SEND_VAL                                                 ~44
         80*       DO_ICALL                                                 
   21    81*       JMP                                                      ->59
         82*       FE_FREE                                                  $35
   26    83*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.23 ms | 1400 KiB | 29 Q