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'), ], ]; // 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'] > strtotime('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'] > strtotime('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 = 24, Position 2 = 47
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 47
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 46
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 46
Branch analysis from position: 46
Branch analysis from position: 35
Branch analysis from position: 46
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/I8nXC
function name:  (null)
number of ops:  52
compiled vars:  !0 = $data, !1 = $currentLeading, !2 = $element, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_ARRAY                                       ~4      16, 'ID'
    6     1        NEW                                              $5      'DateTime'
          2        SEND_VAL_EX                                              '2016-01-01+UTC'
          3        DO_FCALL                                      0          
          4        ADD_ARRAY_ELEMENT                                ~4      $5, 'begin_date'
    7     5        NEW                                              $7      'DateTime'
          6        SEND_VAL_EX                                              '2016-11-30+UTC'
          7        DO_FCALL                                      0          
          8        ADD_ARRAY_ELEMENT                                ~4      $7, 'end_date'
          9        INIT_ARRAY                                       ~9      ~4
   10    10        INIT_ARRAY                                       ~10     33, 'ID'
   11    11        NEW                                              $11     'DateTime'
         12        SEND_VAL_EX                                              '2016-01-04+UTC'
         13        DO_FCALL                                      0          
         14        ADD_ARRAY_ELEMENT                                ~10     $11, 'begin_date'
   12    15        NEW                                              $13     'DateTime'
         16        SEND_VAL_EX                                              '2016-02-29+UTC'
         17        DO_FCALL                                      0          
         18        ADD_ARRAY_ELEMENT                                ~10     $13, 'end_date'
         19        ADD_ARRAY_ELEMENT                                ~9      ~10
    3    20        ASSIGN                                                   !0, ~9
   18    21        FETCH_DIM_R                                      ~16     !0, 0
         22        ASSIGN                                                   !1, ~16
   20    23      > FE_RESET_R                                       $18     !0, ->47
         24    > > FE_FETCH_R                                       ~19     $18, !2, ->47
         25    >   ASSIGN                                                   !3, ~19
   21    26        FETCH_DIM_R                                      ~21     !2, 'begin_date'
         27        INIT_FCALL                                               'strtotime'
         28        SEND_VAL                                                 'now'
         29        DO_ICALL                                         $22     
         30        IS_SMALLER                                               $22, ~21
         31      > JMPZ                                                     ~23, ->46
   23    32    >   IS_EQUAL                                                 !3, 0
         33      > JMPZ                                                     ~24, ->35
   24    34    >   ECHO                                                     'Error%3A+Element+cannot+be+the+leading+element'
   28    35    >   FETCH_DIM_R                                      ~25     !2, 'end_date'
         36        INIT_FCALL                                               'strtotime'
         37        SEND_VAL                                                 'now'
         38        DO_ICALL                                         $26     
         39        IS_SMALLER                                               $26, ~25
         40      > JMPZ                                                     ~27, ->46
   29    41    >   FETCH_DIM_R                                      ~28     !2, 'end_date'
         42        FETCH_DIM_R                                      ~29     !1, 'end_date'
         43        IS_SMALLER                                               ~29, ~28
         44      > JMPZ                                                     ~30, ->46
   30    45    >   ASSIGN                                                   !1, !2
   20    46    > > JMP                                                      ->24
         47    >   FE_FREE                                                  $18
   35    48        INIT_FCALL                                               'var_dump'
         49        SEND_VAR                                                 !1
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.73 ms | 945 KiB | 18 Q