3v4l.org

run code in 300+ PHP versions simultaneously
<?php function toValid($var) { return strtotime(str_replace('.', ':', sprintf('%.2f', $var))); } function getNearest($arr, $var) { $given = toValid($var); $array = array_map('toValid', $arr); $distance = PHP_INT_MAX; $index = -1; for ($c = 0; $c < count($array); $c++) { $c_distance = $array[$c] - $given; if ($c_distance > 0 && $distance > $c_distance) { $distance = $c_distance; $index = $c; } } return $index < 0 ? $var : $array[$index]; } echo date('H.i', getNearest([14.49, 17.57, 12.30, 19.22], '13.30')); echo "\n"; echo date('H.i', getNearest([14.49, 17.57, 12.30, 19.22], '12.30')); echo "\n"; echo date('H.i', getNearest([14.49, 17.57, 12.30, 19.22], '18.30')); echo "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Oq8WT
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     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        ECHO                                                     '%0A'
   27    10        INIT_FCALL                                               'date'
         11        SEND_VAL                                                 'H.i'
         12        INIT_FCALL                                               'getnearest'
         13        SEND_VAL                                                 <array>
         14        SEND_VAL                                                 '12.30'
         15        DO_FCALL                                      0  $2      
         16        SEND_VAR                                                 $2
         17        DO_ICALL                                         $3      
         18        ECHO                                                     $3
         19        ECHO                                                     '%0A'
   28    20        INIT_FCALL                                               'date'
         21        SEND_VAL                                                 'H.i'
         22        INIT_FCALL                                               'getnearest'
         23        SEND_VAL                                                 <array>
         24        SEND_VAL                                                 '18.30'
         25        DO_FCALL                                      0  $4      
         26        SEND_VAR                                                 $4
         27        DO_ICALL                                         $5      
         28        ECHO                                                     $5
         29        ECHO                                                     '%0A'
         30      > RETURN                                                   1

Function tovalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Oq8WT
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 = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 15
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 15
Branch analysis from position: 29
Branch analysis from position: 15
Branch analysis from position: 25
Branch analysis from position: 22
filename:       /in/Oq8WT
function name:  getNearest
number of ops:  37
compiled vars:  !0 = $arr, !1 = $var, !2 = $given, !3 = $array, !4 = $distance, !5 = $index, !6 = $c, !7 = $c_distance
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  $8      
          5        ASSIGN                                                   !2, $8
   10     6        INIT_FCALL                                               'array_map'
          7        SEND_VAL                                                 'toValid'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $10     
         10        ASSIGN                                                   !3, $10
   12    11        ASSIGN                                                   !4, 9223372036854775807
   13    12        ASSIGN                                                   !5, -1
   15    13        ASSIGN                                                   !6, 0
         14      > JMP                                                      ->26
   16    15    >   FETCH_DIM_R                                      ~15     !3, !6
         16        SUB                                              ~16     ~15, !2
         17        ASSIGN                                                   !7, ~16
   17    18        IS_SMALLER                                       ~18     0, !7
         19      > JMPZ_EX                                          ~18     ~18, ->22
         20    >   IS_SMALLER                                       ~19     !7, !4
         21        BOOL                                             ~18     ~19
         22    > > JMPZ                                                     ~18, ->25
   18    23    >   ASSIGN                                                   !4, !7
   19    24        ASSIGN                                                   !5, !6
   15    25    >   PRE_INC                                                  !6
         26    >   COUNT                                            ~23     !3
         27        IS_SMALLER                                               !6, ~23
         28      > JMPNZ                                                    ~24, ->15
   23    29    >   IS_SMALLER                                               !5, 0
         30      > JMPZ                                                     ~25, ->33
         31    >   QM_ASSIGN                                        ~26     !1
         32      > JMP                                                      ->35
         33    >   FETCH_DIM_R                                      ~27     !3, !5
         34        QM_ASSIGN                                        ~26     ~27
         35    > > RETURN                                                   ~26
   24    36*     > RETURN                                                   null

End of function getnearest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.88 ms | 1026 KiB | 22 Q