3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = range(0,1000); function find_closest($arr,$x){ sort($arr); $filtered_array = array_filter($arr,function($v)use($x){ return $v < $x; }); return count($filtered_array) > 0 ? end($filtered_array) : "Your Message"; } echo find_closest($arr,17)."\n"; echo find_closest($arr,20)."\n"; echo find_closest($arr,6);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqeqd
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
   13     5        INIT_FCALL                                               'find_closest'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 17
          8        DO_FCALL                                      0  $3      
          9        CONCAT                                           ~4      $3, '%0A'
         10        ECHO                                                     ~4
   14    11        INIT_FCALL                                               'find_closest'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 20
         14        DO_FCALL                                      0  $5      
         15        CONCAT                                           ~6      $5, '%0A'
         16        ECHO                                                     ~6
   15    17        INIT_FCALL                                               'find_closest'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 6
         20        DO_FCALL                                      0  $7      
         21        ECHO                                                     $7
         22      > RETURN                                                   1

Function find_closest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqeqd
function name:  find_closest
number of ops:  23
compiled vars:  !0 = $arr, !1 = $x, !2 = $filtered_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'sort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
    7     5        INIT_FCALL                                               'array_filter'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Faqeqd%3A7%240'
          8        BIND_LEXICAL                                             ~4, !1
    9     9        SEND_VAL                                                 ~4
         10        DO_ICALL                                         $5      
    7    11        ASSIGN                                                   !2, $5
   10    12        COUNT                                            ~7      !2
         13        IS_SMALLER                                               0, ~7
         14      > JMPZ                                                     ~8, ->20
         15    >   INIT_FCALL                                               'end'
         16        SEND_REF                                                 !2
         17        DO_ICALL                                         $9      
         18        QM_ASSIGN                                        ~10     $9
         19      > JMP                                                      ->21
         20    >   QM_ASSIGN                                        ~10     'Your+Message'
         21    > > RETURN                                                   ~10
   11    22*     > RETURN                                                   null

End of function find_closest

Function %00%7Bclosure%7D%2Fin%2Faqeqd%3A7%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aqeqd
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v, !1 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    8     2        IS_SMALLER                                       ~2      !0, !1
          3      > RETURN                                                   ~2
    9     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Faqeqd%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.41 ms | 1407 KiB | 24 Q