3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = array("2012-06-11 08:30:49", "2012-06-07 08:03:54", "2012-05-26 23:04:04", "2012-05-27 08:30:00", "2012-06-08 08:30:55", "2012-06-12 07:45:45"); $children = array("callum" => "1028", "daniel" => "1029"); $closeDate = array(); $firstDate = strtotime("2012-05-29 07:45:45"); function returnClosestDate($firstTime, $dates, $closeDate, $child){ global $initialLoop; foreach ($dates as $key => $date) { $dateToCompare = strtotime($date); $diff = $firstTime - $dateToCompare; if ($diff < 0) $diff *= -1; if (count($closeDate) == 0) { $closeDate[] = array("date" => $date, "diff" => $diff); continue; } print_r($closeDate); if(!alreadyExistInArray($closeDate, $date)){ if ($diff < $closeDate) { $closeDate[] = array("date" => $date, "diff" => $diff); } } } exit; } function alreadyExistInArray($closeDate, $date){ foreach($closeDate as $key => $close){ print_r($key[$close]); exit; if($close["date"] === $date) return true; } } foreach($children as $key => $child){ returnClosestDate($firstDate, $dates, $closeDate, $child); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/A9opS
function name:  (null)
number of ops:  19
compiled vars:  !0 = $dates, !1 = $children, !2 = $closeDate, !3 = $firstDate, !4 = $child, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        INIT_FCALL                                               'strtotime'
          4        SEND_VAL                                                 '2012-05-29+07%3A45%3A45'
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !3, $9
   36     7      > FE_RESET_R                                       $11     !1, ->17
          8    > > FE_FETCH_R                                       ~12     $11, !4, ->17
          9    >   ASSIGN                                                   !5, ~12
   37    10        INIT_FCALL                                               'returnclosestdate'
         11        SEND_VAR                                                 !3
         12        SEND_VAR                                                 !0
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !4
         15        DO_FCALL                                      0          
   36    16      > JMP                                                      ->8
         17    >   FE_FREE                                                  $11
   38    18      > RETURN                                                   1

Function returnclosestdate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 41
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 41
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 40
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 40
Branch analysis from position: 40
Branch analysis from position: 17
Branch analysis from position: 41
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 41
filename:       /in/A9opS
function name:  returnClosestDate
number of ops:  44
compiled vars:  !0 = $firstTime, !1 = $dates, !2 = $closeDate, !3 = $child, !4 = $initialLoop, !5 = $date, !6 = $key, !7 = $dateToCompare, !8 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    8     4        BIND_GLOBAL                                              !4, 'initialLoop'
    9     5      > FE_RESET_R                                       $9      !1, ->41
          6    > > FE_FETCH_R                                       ~10     $9, !5, ->41
          7    >   ASSIGN                                                   !6, ~10
   10     8        INIT_FCALL                                               'strtotime'
          9        SEND_VAR                                                 !5
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !7, $12
   11    12        SUB                                              ~14     !0, !7
         13        ASSIGN                                                   !8, ~14
   13    14        IS_SMALLER                                               !8, 0
         15      > JMPZ                                                     ~16, ->17
         16    >   ASSIGN_OP                                     3          !8, -1
   15    17    >   COUNT                                            ~18     !2
         18        IS_EQUAL                                                 ~18, 0
         19      > JMPZ                                                     ~19, ->25
   16    20    >   INIT_ARRAY                                       ~21     !5, 'date'
         21        ADD_ARRAY_ELEMENT                                ~21     !8, 'diff'
         22        ASSIGN_DIM                                               !2
         23        OP_DATA                                                  ~21
   17    24      > JMP                                                      ->6
   19    25    >   INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
   20    28        INIT_FCALL_BY_NAME                                       'alreadyExistInArray'
         29        SEND_VAR_EX                                              !2
         30        SEND_VAR_EX                                              !5
         31        DO_FCALL                                      0  $23     
         32        BOOL_NOT                                         ~24     $23
         33      > JMPZ                                                     ~24, ->40
   21    34    >   IS_SMALLER                                               !8, !2
         35      > JMPZ                                                     ~25, ->40
   22    36    >   INIT_ARRAY                                       ~27     !5, 'date'
         37        ADD_ARRAY_ELEMENT                                ~27     !8, 'diff'
         38        ASSIGN_DIM                                               !2
         39        OP_DATA                                                  ~27
    9    40    > > JMP                                                      ->6
         41    >   FE_FREE                                                  $9
   26    42      > EXIT                                                     
   27    43*     > RETURN                                                   null

End of function returnclosestdate

Function alreadyexistinarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/A9opS
function name:  alreadyExistInArray
number of ops:  18
compiled vars:  !0 = $closeDate, !1 = $date, !2 = $close, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   30     2      > FE_RESET_R                                       $4      !0, ->16
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->16
          4    >   ASSIGN                                                   !3, ~5
   31     5        INIT_FCALL                                               'print_r'
          6        FETCH_DIM_R                                      ~7      !3, !2
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                                 
          9      > EXIT                                                     
   32    10*       FETCH_DIM_R                                      ~9      !2, 'date'
         11*       IS_IDENTICAL                                             !1, ~9
         12*       JMPZ                                                     ~10, ->15
         13*       FE_FREE                                                  $4
         14*       RETURN                                                   <true>
   30    15*       JMP                                                      ->3
         16    >   FE_FREE                                                  $4
   34    17      > RETURN                                                   null

End of function alreadyexistinarray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.86 ms | 1407 KiB | 18 Q