3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = array ( '0' => "2013-02-18 05:14:54", '1' => "2013-02-12 01:44:03", '2' => "2013-02-05 16:25:07", '3' => "2013-01-29 02:00:15", '4' => "2013-01-27 18:33:45" ); function closest($dates, $findate) { $newDates = array(); foreach($dates as $date) { $newDates[] = strtotime($date); } echo "<pre>"; print_r($newDates); echo "</pre>"; sort($newDates); foreach ($newDates as $key=>$a) { if ($a >= strtotime($findate)) return $key; } return $key; } $values = closest($dates, date('2013-01-28 14:11:16')); echo $values;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/C3cSl
function name:  (null)
number of ops:  11
compiled vars:  !0 = $dates, !1 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_FCALL                                               'closest'
          2        SEND_VAR                                                 !0
          3        INIT_FCALL                                               'date'
          4        SEND_VAL                                                 '2013-01-28+14%3A11%3A16'
          5        DO_ICALL                                         $3      
          6        SEND_VAR                                                 $3
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !1, $4
   34     9        ECHO                                                     !1
         10      > RETURN                                                   1

Function closest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 31
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 31
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 11
filename:       /in/C3cSl
function name:  closest
number of ops:  34
compiled vars:  !0 = $dates, !1 = $findate, !2 = $newDates, !3 = $date, !4 = $a, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        ASSIGN                                                   !2, <array>
   15     3      > FE_RESET_R                                       $7      !0, ->11
          4    > > FE_FETCH_R                                               $7, !3, ->11
   17     5    >   INIT_FCALL                                               'strtotime'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $9      
          8        ASSIGN_DIM                                               !2
          9        OP_DATA                                                  $9
   15    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $7
   20    12        ECHO                                                     '%3Cpre%3E'
   21    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
   22    16        ECHO                                                     '%3C%2Fpre%3E'
   24    17        INIT_FCALL                                               'sort'
         18        SEND_REF                                                 !2
         19        DO_ICALL                                                 
   25    20      > FE_RESET_R                                       $12     !2, ->31
         21    > > FE_FETCH_R                                       ~13     $12, !4, ->31
         22    >   ASSIGN                                                   !5, ~13
   27    23        INIT_FCALL                                               'strtotime'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $15     
         26        IS_SMALLER_OR_EQUAL                                      $15, !4
         27      > JMPZ                                                     ~16, ->30
   28    28    >   FE_FREE                                                  $12
         29      > RETURN                                                   !5
   25    30    > > JMP                                                      ->21
         31    >   FE_FREE                                                  $12
   30    32      > RETURN                                                   !5
   31    33*     > RETURN                                                   null

End of function closest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.44 ms | 1407 KiB | 22 Q