3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array( 0 => 15, 1 => 6, 2 => 19, 3 => 21, 4 => 18 ); function closest($arr, $x) { $result = "default"; sort($arr); foreach($arr as $value) { if($value < $x) { $result = $value; } else break; } return $result; } echo closest($arr,17)."\n"; echo closest($arr,20)."\n"; echo closest($arr,6);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ka9rF
function name:  (null)
number of ops:  19
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'closest'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 17
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        ECHO                                                     ~3
   25     7        INIT_FCALL                                               'closest'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 20
         10        DO_FCALL                                      0  $4      
         11        CONCAT                                           ~5      $4, '%0A'
         12        ECHO                                                     ~5
   26    13        INIT_FCALL                                               'closest'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 6
         16        DO_FCALL                                      0  $6      
         17        ECHO                                                     $6
         18      > RETURN                                                   1

Function closest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 14
filename:       /in/ka9rF
function name:  closest
number of ops:  17
compiled vars:  !0 = $arr, !1 = $x, !2 = $result, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN                                                   !2, 'default'
   13     3        INIT_FCALL                                               'sort'
          4        SEND_REF                                                 !0
          5        DO_ICALL                                                 
   15     6      > FE_RESET_R                                       $6      !0, ->14
          7    > > FE_FETCH_R                                               $6, !3, ->14
   16     8    >   IS_SMALLER                                               !3, !1
          9      > JMPZ                                                     ~7, ->12
   17    10    >   ASSIGN                                                   !2, !3
   16    11      > JMP                                                      ->13
   19    12    > > JMP                                                      ->14
   15    13    > > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   21    15      > RETURN                                                   !2
   22    16*     > RETURN                                                   null

End of function closest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.55 ms | 1018 KiB | 17 Q