3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundRating($rating, $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/E4KEC
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 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 18
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/E4KEC
function name:  roundRating
number of ops:  21
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        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $4      
          6      > JMPZ                                                     $4, ->8
    7     7    > > RETURN                                                   !0
   10     8    > > FE_RESET_R                                       $5      !1, ->18
          9    > > FE_FETCH_R                                       ~6      $5, !2, ->18
         10    >   ASSIGN                                                   !3, ~6
   12    11        IS_SMALLER                                               !0, !2
         12      > JMPZ                                                     ~8, ->17
   14    13    >   SUB                                              ~9      !3, 1
         14        FETCH_DIM_R                                      ~10     !1, ~9
         15        FE_FREE                                                  $5
         16      > RETURN                                                   ~10
   10    17    > > JMP                                                      ->9
         18    >   FE_FREE                                                  $5
   17    19      > RETURN                                                   <false>
   18    20*     > RETURN                                                   null

End of function roundrating

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.63 ms | 1403 KiB | 18 Q