3v4l.org

run code in 300+ 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:  15
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                                               'str_replace'
          3        SEND_VAL                                                 '.'
          4        SEND_VAL                                                 '%3A'
          5        INIT_FCALL                                               'sprintf'
          6        SEND_VAL                                                 '%25.2f'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $1      
          9        SEND_VAR                                                 $1
         10        DO_ICALL                                         $2      
         11        SEND_VAR                                                 $2
         12        DO_ICALL                                         $3      
         13      > RETURN                                                   $3
    5    14*     > 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                                  '%00%7Bclosure%7D%2Fin%2F8uROA%3A12%240'
         14        BIND_LEXICAL                                             ~6, !1
   14    15        SEND_VAL                                                 ~6
         16        DO_ICALL                                                 
   16    17        INIT_FCALL                                               'array_shift'
         18        SEND_REF                                                 !0
         19        DO_ICALL                                         $8      
         20      > RETURN                                                   $8
   17    21*     > RETURN                                                   null

End of function getnearest

Function %00%7Bclosure%7D%2Fin%2F8uROA%3A12%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8uROA
function name:  {closure}
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 function %00%7Bclosure%7D%2Fin%2F8uROA%3A12%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.11 ms | 1403 KiB | 31 Q