3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ [ 'date' => '2023-11-01', 'MinStay' => 1 ], [ 'date' => '2023-11-02', 'MinStay' => 1 ], [ 'date' => '2023-11-03', 'MinStay' => 1 ], [ 'date' => '2023-11-04', 'MinStay' => 2 ], [ 'date' => '2023-11-05', 'MinStay' => 2 ], [ 'date' => '2023-11-06', 'MinStay' => 2 ], [ 'date' => '2023-12-10', 'MinStay' => 1 ], [ 'date' => '2023-12-11', 'MinStay' => 1 ], [ 'date' => '2023-12-12', 'MinStay' => 3 ], [ 'date' => '2023-12-13', 'MinStay' => 2 ], [ 'date' => '2023-12-14', 'MinStay' => 2 ], [ 'date' => '2023-12-24', 'MinStay' => 2 ], // <-- added challenge where same minstay is not on contiguous date [ 'date' => '2024-01-01', 'MinStay' => 4 ], [ 'date' => '2024-01-02', 'MinStay' => 4 ], [ 'date' => '2024-01-03', 'MinStay' => 4 ], [ 'date' => '2024-01-04', 'MinStay' => 4 ], ]; $result = []; $lastMinStay = null; foreach ($input as ['date' => $d, 'MinStay' => $ms]) { if ($ms !== $lastMinStay || $d !== date('Y-m-d', strtotime("{$ref['dateTo']} +1 day"))) { unset($ref); $ref = ['dateFrom' => $d, 'dateTo' => $d, 'MinStay' => $ms]; $result[] =& $ref; $lastMinStay = $ms; continue; } $ref['dateTo'] = $d; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 37
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/4vfhq
function name:  (null)
number of ops:  42
compiled vars:  !0 = $input, !1 = $result, !2 = $lastMinStay, !3 = $d, !4 = $ms, !5 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                                   !1, <array>
   23     2        ASSIGN                                                   !2, null
   24     3      > FE_RESET_R                                       $9      !0, ->37
          4    > > FE_FETCH_R                                               $9, $10, ->37
          5    >   FETCH_LIST_R                                     $11     $10, 'date'
          6        ASSIGN                                                   !3, $11
          7        FETCH_LIST_R                                     $13     $10, 'MinStay'
          8        ASSIGN                                                   !4, $13
          9        FREE                                                     $10
   25    10        IS_NOT_IDENTICAL                                 ~15     !4, !2
         11      > JMPNZ_EX                                         ~15     ~15, ->24
         12    >   INIT_FCALL                                               'date'
         13        SEND_VAL                                                 'Y-m-d'
         14        INIT_FCALL                                               'strtotime'
         15        FETCH_DIM_R                                      ~16     !5, 'dateTo'
         16        NOP                                                      
         17        FAST_CONCAT                                      ~17     ~16, '+%2B1+day'
         18        SEND_VAL                                                 ~17
         19        DO_ICALL                                         $18     
         20        SEND_VAR                                                 $18
         21        DO_ICALL                                         $19     
         22        IS_NOT_IDENTICAL                                 ~20     !3, $19
         23        BOOL                                             ~15     ~20
         24    > > JMPZ                                                     ~15, ->34
   26    25    >   UNSET_CV                                                 !5
   27    26        INIT_ARRAY                                       ~21     !3, 'dateFrom'
         27        ADD_ARRAY_ELEMENT                                ~21     !3, 'dateTo'
         28        ADD_ARRAY_ELEMENT                                ~21     !4, 'MinStay'
         29        ASSIGN                                                   !5, ~21
   28    30        FETCH_DIM_W                                      $23     !1
         31        ASSIGN_REF                                               $23, !5
   29    32        ASSIGN                                                   !2, !4
   30    33      > JMP                                                      ->4
   32    34    >   ASSIGN_DIM                                               !5, 'dateTo'
         35        OP_DATA                                                  !3
   24    36      > JMP                                                      ->4
         37    >   FE_FREE                                                  $9
   34    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.06 ms | 1017 KiB | 16 Q