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'), ], ]; $currentLeading = null; 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 = 23, Position 2 = 44
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 44
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 43
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 43
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 43
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 43
Branch analysis from position: 43
Branch analysis from position: 33
Branch analysis from position: 43
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/QCVWf
function name:  (null)
number of ops:  49
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
   16    21        ASSIGN                                                   !1, null
   17    22      > FE_RESET_R                                       $17     !0, ->44
         23    > > FE_FETCH_R                                       ~18     $17, !2, ->44
         24    >   ASSIGN                                                   !3, ~18
   18    25        FETCH_DIM_R                                      ~20     !2, 'begin_date'
         26        INIT_FCALL_BY_NAME                                       'now'
         27        DO_FCALL                                      0  $21     
         28        IS_SMALLER                                               $21, ~20
         29      > JMPZ                                                     ~22, ->43
   20    30    >   IS_EQUAL                                                 !3, 0
         31      > JMPZ                                                     ~23, ->33
   21    32    >   ECHO                                                     'Error%3A+Element+cannot+be+the+leading+element'
   25    33    >   FETCH_DIM_R                                      ~24     !2, 'end_date'
         34        INIT_FCALL_BY_NAME                                       'now'
         35        DO_FCALL                                      0  $25     
         36        IS_SMALLER                                               $25, ~24
         37      > JMPZ                                                     ~26, ->43
   26    38    >   FETCH_DIM_R                                      ~27     !2, 'end_date'
         39        FETCH_DIM_R                                      ~28     !1, 'end_date'
         40        IS_SMALLER                                               ~28, ~27
         41      > JMPZ                                                     ~29, ->43
   27    42    >   ASSIGN                                                   !1, !2
   17    43    > > JMP                                                      ->23
         44    >   FE_FREE                                                  $17
   32    45        INIT_FCALL                                               'var_dump'
         46        SEND_VAR                                                 !1
         47        DO_ICALL                                                 
         48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.9 ms | 1405 KiB | 15 Q