3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ [ 'ID' => 16, 'begin_date' => new \DateTime('2016-01-01 UTC'), 'end_date' => new \DateTime('2016-11-30 UTC'), ], [ 'ID' => 33, 'begin_date' => new \DateTime('2016-01-04 UTC'), 'end_date' => new \DateTime('2016-02-29 UTC'), ], ]; // for programs that run over multiple seconds this makes sure we don't drift during sorting $now = new \DateTime(strtotime('now')); // assume length >= 1 w/ previous validation // keep track of the in-progress leading element, assuming the first is leading to begin with $currentLeading = $data[0]; foreach($data as $index => $element) { if($element['begin_date'] > $now) { // first condition is true if ($index == 0) { echo "Error: Element cannot be the leading element"; // more likely return false if wrapped in a validation function } if($element['end_date'] > $now) { if ($element['end_date'] > $currentLeading['end_date']) { $currentLeading = $element; } } } } var_dump($currentLeading);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 48
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 48
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 47
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 39
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 47
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 47
Branch analysis from position: 47
Branch analysis from position: 39
Branch analysis from position: 47
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
filename:       /in/048kZ
function name:  (null)
number of ops:  53
compiled vars:  !0 = $data, !1 = $now, !2 = $currentLeading, !3 = $element, !4 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_ARRAY                                       ~5      16, 'ID'
    6     1        NEW                                              $6      'DateTime'
          2        SEND_VAL_EX                                              '2016-01-01+UTC'
          3        DO_FCALL                                      0          
          4        ADD_ARRAY_ELEMENT                                ~5      $6, 'begin_date'
    7     5        NEW                                              $8      'DateTime'
          6        SEND_VAL_EX                                              '2016-11-30+UTC'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~5      $8, 'end_date'
          9        INIT_ARRAY                                       ~10     ~5
   10    10        INIT_ARRAY                                       ~11     33, 'ID'
   11    11        NEW                                              $12     'DateTime'
         12        SEND_VAL_EX                                              '2016-01-04+UTC'
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~11     $12, 'begin_date'
   12    15        NEW                                              $14     'DateTime'
         16        SEND_VAL_EX                                              '2016-02-29+UTC'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~11     $14, 'end_date'
         19        ADD_ARRAY_ELEMENT                                ~10     ~11
    3    20        ASSIGN                                                   !0, ~10
   17    21        NEW                                              $17     'DateTime'
         22        INIT_FCALL                                               'strtotime'
         23        SEND_VAL                                                 'now'
         24        DO_ICALL                                         $18     
         25        SEND_VAR_NO_REF_EX                                       $18
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !1, $17
   21    28        FETCH_DIM_R                                      ~21     !0, 0
         29        ASSIGN                                                   !2, ~21
   23    30      > FE_RESET_R                                       $23     !0, ->48
         31    > > FE_FETCH_R                                       ~24     $23, !3, ->48
         32    >   ASSIGN                                                   !4, ~24
   24    33        FETCH_DIM_R                                      ~26     !3, 'begin_date'
         34        IS_SMALLER                                               !1, ~26
         35      > JMPZ                                                     ~27, ->47
   26    36    >   IS_EQUAL                                                 !4, 0
         37      > JMPZ                                                     ~28, ->39
   27    38    >   ECHO                                                     'Error%3A+Element+cannot+be+the+leading+element'
   31    39    >   FETCH_DIM_R                                      ~29     !3, 'end_date'
         40        IS_SMALLER                                               !1, ~29
         41      > JMPZ                                                     ~30, ->47
   32    42    >   FETCH_DIM_R                                      ~31     !3, 'end_date'
         43        FETCH_DIM_R                                      ~32     !2, 'end_date'
         44        IS_SMALLER                                               ~32, ~31
         45      > JMPZ                                                     ~33, ->47
   33    46    >   ASSIGN                                                   !2, !3
   23    47    > > JMP                                                      ->31
         48    >   FE_FREE                                                  $23
   38    49        INIT_FCALL                                               'var_dump'
         50        SEND_VAR                                                 !2
         51        DO_ICALL                                                 
         52      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.49 ms | 1392 KiB | 17 Q