3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr_dates = array(20150616,20150615,20150612,20150611,20150610,20150609,20150608,20150605,20150604,20150603,20150602,20150601,20150529,20150528,20150521,20150514,20150507,20150430,20150423,20150416,20150409,20150402,20150326); $current_date = 20150616; $expected_trend_date = 20150516; $expected_result = 20150514; $trend_index = 0; $last_diff = 100000; foreach ($arr_dates as $index => $date) { $diff = abs($date - $expected_trend_date); echo $diff, ':', $date, PHP_EOL; if ($diff < $last_diff) { $last_diff = $diff; } else { $trend_index = $index; break; } } echo $arr_dates[$trend_index];
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 25
filename:       /in/NGOXu
function name:  (null)
number of ops:  29
compiled vars:  !0 = $arr_dates, !1 = $current_date, !2 = $expected_trend_date, !3 = $expected_result, !4 = $trend_index, !5 = $last_diff, !6 = $date, !7 = $index, !8 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, 20150616
    6     2        ASSIGN                                                   !2, 20150516
    7     3        ASSIGN                                                   !3, 20150514
    9     4        ASSIGN                                                   !4, 0
   10     5        ASSIGN                                                   !5, 100000
   12     6      > FE_RESET_R                                       $15     !0, ->25
          7    > > FE_FETCH_R                                       ~16     $15, !6, ->25
          8    >   ASSIGN                                                   !7, ~16
   14     9        INIT_FCALL                                               'abs'
         10        SUB                                              ~18     !6, !2
         11        SEND_VAL                                                 ~18
         12        DO_ICALL                                         $19     
         13        ASSIGN                                                   !8, $19
   15    14        ECHO                                                     !8
         15        ECHO                                                     '%3A'
         16        ECHO                                                     !6
         17        ECHO                                                     '%0A'
   17    18        IS_SMALLER                                               !8, !5
         19      > JMPZ                                                     ~21, ->22
   19    20    >   ASSIGN                                                   !5, !8
         21      > JMP                                                      ->24
   23    22    >   ASSIGN                                                   !4, !7
   24    23      > JMP                                                      ->25
   12    24    > > JMP                                                      ->7
         25    >   FE_FREE                                                  $15
   28    26        FETCH_DIM_R                                      ~24     !0, !4
         27        ECHO                                                     ~24
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.64 ms | 1396 KiB | 15 Q