3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundNearest($decimal, $nearest){ $int = intval($decimal); $currDecimal = $int + $nearest; $nextDecimal = $int + 1 + $nearest; if(abs($decimal - $currDecimal) <= abs($nextDecimal - $decimal)) return $currDecimal; return $nextDecimal; } echo roundNearest('45.67', '0.43'), PHP_EOL; echo roundNearest('34.98', '0.13'), PHP_EOL; echo roundNearest('34.98', '0.43'), PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b3rjk
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'roundnearest'
          1        SEND_VAL                                                 '45.67'
          2        SEND_VAL                                                 '0.43'
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
          5        ECHO                                                     '%0A'
   12     6        INIT_FCALL                                               'roundnearest'
          7        SEND_VAL                                                 '34.98'
          8        SEND_VAL                                                 '0.13'
          9        DO_FCALL                                      0  $1      
         10        ECHO                                                     $1
         11        ECHO                                                     '%0A'
   13    12        INIT_FCALL                                               'roundnearest'
         13        SEND_VAL                                                 '34.98'
         14        SEND_VAL                                                 '0.43'
         15        DO_FCALL                                      0  $2      
         16        ECHO                                                     $2
         17        ECHO                                                     '%0A'
   14    18      > RETURN                                                   1

Function roundnearest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b3rjk
function name:  roundNearest
number of ops:  22
compiled vars:  !0 = $decimal, !1 = $nearest, !2 = $int, !3 = $currDecimal, !4 = $nextDecimal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        CAST                                          4  ~5      !0
          3        ASSIGN                                                   !2, ~5
    5     4        ADD                                              ~7      !2, !1
          5        ASSIGN                                                   !3, ~7
    6     6        ADD                                              ~9      !2, 1
          7        ADD                                              ~10     ~9, !1
          8        ASSIGN                                                   !4, ~10
    7     9        INIT_FCALL                                               'abs'
         10        SUB                                              ~12     !0, !3
         11        SEND_VAL                                                 ~12
         12        DO_ICALL                                         $13     
         13        INIT_FCALL                                               'abs'
         14        SUB                                              ~14     !4, !0
         15        SEND_VAL                                                 ~14
         16        DO_ICALL                                         $15     
         17        IS_SMALLER_OR_EQUAL                                      $13, $15
         18      > JMPZ                                                     ~16, ->20
         19    > > RETURN                                                   !3
    8    20    > > RETURN                                                   !4
    9    21*     > RETURN                                                   null

End of function roundnearest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.77 ms | 1444 KiB | 17 Q