3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = range(0,1000); 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/sa2fv
function name:  (null)
number of ops:  23
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 0
          2        SEND_VAL                                                 1000
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   18     5        INIT_FCALL                                               'closest'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 17
          8        DO_FCALL                                      0  $3      
          9        CONCAT                                           ~4      $3, '%0A'
         10        ECHO                                                     ~4
   19    11        INIT_FCALL                                               'closest'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 20
         14        DO_FCALL                                      0  $5      
         15        CONCAT                                           ~6      $5, '%0A'
         16        ECHO                                                     ~6
   20    17        INIT_FCALL                                               'closest'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 6
         20        DO_FCALL                                      0  $7      
         21        ECHO                                                     $7
         22      > 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/sa2fv
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
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        ASSIGN                                                   !2, 'default'
    7     3        INIT_FCALL                                               'sort'
          4        SEND_REF                                                 !0
          5        DO_ICALL                                                 
    9     6      > FE_RESET_R                                       $6      !0, ->14
          7    > > FE_FETCH_R                                               $6, !3, ->14
   10     8    >   IS_SMALLER                                               !3, !1
          9      > JMPZ                                                     ~7, ->12
   11    10    >   ASSIGN                                                   !2, !3
   10    11      > JMP                                                      ->13
   13    12    > > JMP                                                      ->14
    9    13    > > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   15    15      > RETURN                                                   !2
   16    16*     > RETURN                                                   null

End of function closest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
195.53 ms | 1468 KiB | 18 Q