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('2015-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('now'); usort($data, function($a, $b) { // Note PHP 7 <=> doesn't work on \DateTime if($a['end_date'] == $b['end_date']) { return 0; } return $a['end_date'] > $b['end_date'] ? 1 : -1; }); var_dump($now); var_dump($data); // pick the first element that meets the criteria foreach($data as $index => $element) { if($element['begin_date'] < $now) { // first condition is invalidated echo "begin_date invalidated ID #".$element['ID'].PHP_EOL; continue; } else { var_dump($element); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 37, Position 2 = 52
Branch analysis from position: 37
2 jumps found. (Code = 78) Position 1 = 38, Position 2 = 52
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/s67NV
function name:  (null)
number of ops:  54
compiled vars:  !0 = $data, !1 = $now, !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                                              '2015-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
   17    21        NEW                                              $16     'DateTime'
         22        SEND_VAL_EX                                              'now'
         23        DO_FCALL                                      0          
         24        ASSIGN                                                   !1, $16
   19    25        INIT_FCALL                                               'usort'
         26        SEND_REF                                                 !0
         27        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fs67NV%3A19%240'
   25    28        SEND_VAL                                                 ~19
         29        DO_ICALL                                                 
   27    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                                 
   28    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                                 
   31    36      > FE_RESET_R                                       $23     !0, ->52
         37    > > FE_FETCH_R                                       ~24     $23, !2, ->52
         38    >   ASSIGN                                                   !3, ~24
   32    39        FETCH_DIM_R                                      ~26     !2, 'begin_date'
         40        IS_SMALLER                                               ~26, !1
         41      > JMPZ                                                     ~27, ->48
   34    42    >   FETCH_DIM_R                                      ~28     !2, 'ID'
         43        CONCAT                                           ~29     'begin_date+invalidated+ID+%23', ~28
         44        CONCAT                                           ~30     ~29, '%0A'
         45        ECHO                                                     ~30
   35    46      > JMP                                                      ->37
         47*       JMP                                                      ->51
   38    48    >   INIT_FCALL                                               'var_dump'
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                                 
   31    51      > JMP                                                      ->37
         52    >   FE_FREE                                                  $23
   40    53      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fs67NV%3A19%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/s67NV
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        FETCH_DIM_R                                      ~2      !0, 'end_date'
          3        FETCH_DIM_R                                      ~3      !1, 'end_date'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   22     6    > > RETURN                                                   0
   24     7    >   FETCH_DIM_R                                      ~5      !0, 'end_date'
          8        FETCH_DIM_R                                      ~6      !1, 'end_date'
          9        IS_SMALLER                                               ~6, ~5
         10      > JMPZ                                                     ~7, ->13
         11    >   QM_ASSIGN                                        ~8      1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~8      -1
         14    > > RETURN                                                   ~8
   25    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fs67NV%3A19%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.5 ms | 1400 KiB | 17 Q