3v4l.org

run code in 500+ PHP versions simultaneously
<?php function roundRating($rating, array $ratings) { if (in_array($rating, $ratings)) { return $rating; } foreach($ratings as $key => $value) { if ($value > $rating) { return $ratings[($key - 1)]; } } return FALSE; } $ratings = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]; $rating = 4.3; if ($rate = roundRating($rating, $ratings)) echo sprintf('%.01f', $rate);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/J5Zc1
function name:  (null)
number of ops:  14
compiled vars:  !0 = $ratings, !1 = $rating, !2 = $rate
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                       !0, <array>
   21     1        ASSIGN                                                       !1, 4.3
   23     2        INIT_FCALL                                                   'roundrating'
          3        SEND_VAR                                                     !1
          4        SEND_VAR                                                     !0
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                               ~6      !2, $5
          7      > JMPZ                                                         ~6, ->13
   24     8    >   INIT_FCALL                                                   'sprintf'
          9        SEND_VAL                                                     '%25.01f'
         10        SEND_VAR                                                     !2
         11        DO_ICALL                                             $7      
         12        ECHO                                                         $7
         13    > > RETURN                                                       1

Function roundrating:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/J5Zc1
function name:  roundRating
number of ops:  18
compiled vars:  !0 = $rating, !1 = $ratings, !2 = $value, !3 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        FRAMELESS_ICALL_2                in_array            ~4      !0, !1
          3      > JMPZ                                                         ~4, ->5
    7     4    > > RETURN                                                       !0
   10     5    > > FE_RESET_R                                           $5      !1, ->15
          6    > > FE_FETCH_R                                           ~6      $5, !2, ->15
          7    >   ASSIGN                                                       !3, ~6
   12     8        IS_SMALLER                                                   !0, !2
          9      > JMPZ                                                         ~8, ->14
   14    10    >   SUB                                                  ~9      !3, 1
         11        FETCH_DIM_R                                          ~10     !1, ~9
         12        FE_FREE                                                      $5
         13      > RETURN                                                       ~10
   10    14    > > JMP                                                          ->6
         15    >   FE_FREE                                                      $5
   17    16      > RETURN                                                       <false>
   18    17*     > RETURN                                                       null

End of function roundrating

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
142.29 ms | 3043 KiB | 16 Q