3v4l.org

run code in 500+ PHP versions simultaneously
<?php function toValid($var) { return strtotime(str_replace('.', ':', sprintf('%.2f', $var))); } function getNearest($arr, $var) { $var = toValid($var); $arr = array_map('toValid', $arr); usort($arr, function($a, $b) use ($var) { return abs($a - $var) - abs($b - $var); }); return array_shift($arr); } echo date('H.i', getNearest([14.49,17.57,12.30,19.22], '13.30'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8uROA
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                                   'date'
          1        SEND_VAL                                                     'H.i'
          2        INIT_FCALL                                                   'getnearest'
          3        SEND_VAL                                                     <array>
          4        SEND_VAL                                                     '13.30'
          5        DO_FCALL                                          0  $0      
          6        SEND_VAR                                                     $0
          7        DO_ICALL                                             $1      
          8        ECHO                                                         $1
          9      > RETURN                                                       1

Function tovalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8uROA
function name:  toValid
number of ops:  12
compiled vars:  !0 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        INIT_FCALL                                                   'strtotime'
          2        INIT_FCALL                                                   'sprintf'
          3        SEND_VAL                                                     '%25.2f'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                             $1      
          6        FRAMELESS_ICALL_3                str_replace         ~2      '.', '%3A'
          7        OP_DATA                                                      $1
          8        SEND_VAL                                                     ~2
          9        DO_ICALL                                             $3      
         10      > RETURN                                                       $3
    5    11*     > RETURN                                                       null

End of function tovalid

Function getnearest:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8uROA
function name:  getNearest
number of ops:  22
compiled vars:  !0 = $arr, !1 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    9     2        INIT_FCALL                                                   'tovalid'
          3        SEND_VAR                                                     !1
          4        DO_FCALL                                          0  $2      
          5        ASSIGN                                                       !1, $2
   10     6        INIT_FCALL                                                   'array_map'
          7        SEND_VAL                                                     'toValid'
          8        SEND_VAR                                                     !0
          9        DO_ICALL                                             $4      
         10        ASSIGN                                                       !0, $4
   12    11        INIT_FCALL                                                   'usort'
         12        SEND_REF                                                     !0
         13        DECLARE_LAMBDA_FUNCTION                              ~6      [0]
         14        BIND_LEXICAL                                                 ~6, !1
   14    15        SEND_VAL                                                     ~6
   12    16        DO_ICALL                                                     
   16    17        INIT_FCALL                                                   'array_shift'
         18        SEND_REF                                                     !0
         19        DO_ICALL                                             $8      
         20      > RETURN                                                       $8
   17    21*     > 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/8uROA
function name:  {closure:getNearest():12}
number of ops:  14
compiled vars:  !0 = $a, !1 = $b, !2 = $var
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   13     3        INIT_FCALL                                                   'abs'
          4        SUB                                                  ~3      !0, !2
          5        SEND_VAL                                                     ~3
          6        DO_ICALL                                             $4      
          7        INIT_FCALL                                                   'abs'
          8        SUB                                                  ~5      !1, !2
          9        SEND_VAL                                                     ~5
         10        DO_ICALL                                             $6      
         11        SUB                                                  ~7      $4, $6
         12      > RETURN                                                       ~7
   14    13*     > RETURN                                                       null

End of Dynamic Function 0

End of function getnearest

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
221.63 ms | 1584 KiB | 17 Q