3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array( 0 => 15, 1 => 6, 2 => 19, 3 => 21, 4 => 18 ); 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/JgmmD
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>
   19     1        INIT_FCALL                                               'find_closest'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 17
          4        DO_FCALL                                      0  $2      
          5        CONCAT                                           ~3      $2, '%0A'
          6        ECHO                                                     ~3
   20     7        INIT_FCALL                                               'find_closest'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 20
         10        DO_FCALL                                      0  $4      
         11        CONCAT                                           ~5      $4, '%0A'
         12        ECHO                                                     ~5
   21    13        INIT_FCALL                                               'find_closest'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 6
         16        DO_FCALL                                      0  $6      
         17        ECHO                                                     $6
         18      > 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/JgmmD
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
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        INIT_FCALL                                               'sort'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   13     5        INIT_FCALL                                               'array_filter'
          6        SEND_VAR                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          8        BIND_LEXICAL                                             ~4, !1
   15     9        SEND_VAL                                                 ~4
   13    10        DO_ICALL                                         $5      
         11        ASSIGN                                                   !2, $5
   16    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
   17    22*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JgmmD
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $v, !1 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   14     2        IS_SMALLER                                       ~2      !0, !1
          3      > RETURN                                                   ~2
   15     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function find_closest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.68 ms | 1014 KiB | 19 Q