3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_closest() { $now = date('Y-m-d'); $date_array = array( '29-10-2018', '4-11-2018', '25-11-2018', '2-12-2018', '16-12-2018', '23-12-2018', '30-12-2018', '27-01-2019', '24-02-2019', '31-03-2019', '14-04-2019', '28-04-2019', '26-05-2019', '30-06-2019', '28-07-2019', '25-08-2019', '29-09-2019', '27-10-2019', '24-11-2019', '15-12-2019', '22-12-2019', '29-12-2019' ); foreach($date_array as $day) { $interval[] = abs(strtotime($now) - strtotime($day)); } asort($interval); $closest = key($interval); return $array[$closest]; } function is_today() { $date_array = array( '29-10-2018', '4-11-2018', '25-11-2018', '2-12-2018', '16-12-2018', '23-12-2018', '30-12-2018', '27-01-2019', '24-02-2019', '31-03-2019', '14-04-2019', '28-04-2019', '26-05-2019', '30-06-2019', '28-07-2019', '25-08-2019', '29-09-2019', '27-10-2019', '24-11-2019', '15-12-2019', '22-12-2019', '29-12-2019' ); $now = date("Y-m-d"); $now_datetime = new DateTime($now); // foreach($date_array as $date) { $match_date = new DateTime($date); $interval = $now_datetime->diff($match_date); if($interval->days === 0) { return true; break; } else { return false; } } } var_dump(find_closest());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3Ecvp
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'find_closest'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
          5      > RETURN                                                   1

Function find_closest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/3Ecvp
function name:  find_closest
number of ops:  31
compiled vars:  !0 = $now, !1 = $date_array, !2 = $day, !3 = $interval, !4 = $closest, !5 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'date'
          1        SEND_VAL                                                 'Y-m-d'
          2        DO_ICALL                                         $6      
          3        ASSIGN                                                   !0, $6
    5     4        ASSIGN                                                   !1, <array>
   30     5      > FE_RESET_R                                       $9      !1, ->20
          6    > > FE_FETCH_R                                               $9, !2, ->20
   31     7    >   INIT_FCALL                                               'abs'
          8        INIT_FCALL                                               'strtotime'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $11     
         11        INIT_FCALL                                               'strtotime'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $12     
         14        SUB                                              ~13     $11, $12
         15        SEND_VAL                                                 ~13
         16        DO_ICALL                                         $14     
         17        ASSIGN_DIM                                               !3
         18        OP_DATA                                                  $14
   30    19      > JMP                                                      ->6
         20    >   FE_FREE                                                  $9
   34    21        INIT_FCALL                                               'asort'
         22        SEND_REF                                                 !3
         23        DO_ICALL                                                 
   35    24        INIT_FCALL                                               'key'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $16     
         27        ASSIGN                                                   !4, $16
   36    28        FETCH_DIM_R                                      ~18     !5, !4
         29      > RETURN                                                   ~18
   37    30*     > RETURN                                                   null

End of function find_closest

Function is_today:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 29
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 29
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/3Ecvp
function name:  is_today
number of ops:  31
compiled vars:  !0 = $date_array, !1 = $now, !2 = $now_datetime, !3 = $date, !4 = $match_date, !5 = $interval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, <array>
   64     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Y-m-d'
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
   65     5        NEW                                              $9      'DateTime'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $9
   67     9      > FE_RESET_R                                       $12     !0, ->29
         10    > > FE_FETCH_R                                               $12, !3, ->29
   68    11    >   NEW                                              $13     'DateTime'
         12        SEND_VAR_EX                                              !3
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !4, $13
   69    15        INIT_METHOD_CALL                                         !2, 'diff'
         16        SEND_VAR_EX                                              !4
         17        DO_FCALL                                      0  $16     
         18        ASSIGN                                                   !5, $16
   70    19        FETCH_OBJ_R                                      ~18     !5, 'days'
         20        IS_IDENTICAL                                             ~18, 0
         21      > JMPZ                                                     ~19, ->26
   71    22    >   FE_FREE                                                  $12
         23      > RETURN                                                   <true>
   72    24*       JMP                                                      ->29
         25*       JMP                                                      ->28
   74    26    >   FE_FREE                                                  $12
         27      > RETURN                                                   <false>
   67    28*       JMP                                                      ->10
         29    >   FE_FREE                                                  $12
   77    30      > RETURN                                                   null

End of function is_today

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.34 ms | 1403 KiB | 26 Q