3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-17', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-18', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'square', 'startdate' => '2011-08-20', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-22', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-20', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-23', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-19', ], ]; usort($array, fn($a, $b) => $a['startdate'] <=> $b['startdate']); $result = []; foreach ($array as $row) { $compositeKey = implode( '_', [$row['color'], $row['size'], $row['shape']] ); if ( !isset($ref[$compositeKey]) || ($row['startdate'] != date('Y-m-d', strtotime(($ref[$compositeKey]['enddate'] ?? $ref[$compositeKey]['startdate']) . ' + 1 day'))) ) { if (isset($ref[$compositeKey])) { unset($ref[$compositeKey]); } $ref[$compositeKey] = $row; $result[] =& $ref[$compositeKey]; } else { $ref[$compositeKey]['enddate'] = $row['startdate']; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 56
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 56
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 23, Position 2 = 40
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 51
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 44
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 40
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/SsuHr
function name:  (null)
number of ops:  61
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $compositeKey, !4 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   48     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          4        SEND_VAL                                                 ~6
          5        DO_ICALL                                                 
   49     6        ASSIGN                                                   !1, <array>
   50     7      > FE_RESET_R                                       $9      !0, ->56
          8    > > FE_FETCH_R                                               $9, !2, ->56
   51     9    >   INIT_FCALL                                               'implode'
   52    10        SEND_VAL                                                 '_'
   53    11        FETCH_DIM_R                                      ~10     !2, 'color'
         12        INIT_ARRAY                                       ~11     ~10
         13        FETCH_DIM_R                                      ~12     !2, 'size'
         14        ADD_ARRAY_ELEMENT                                ~11     ~12
         15        FETCH_DIM_R                                      ~13     !2, 'shape'
         16        ADD_ARRAY_ELEMENT                                ~11     ~13
         17        SEND_VAL                                                 ~11
   51    18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !3, $14
   56    20        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !4, !3
         21        BOOL_NOT                                         ~17     ~16
         22      > JMPNZ_EX                                         ~17     ~17, ->40
   57    23    >   FETCH_DIM_R                                      ~18     !2, 'startdate'
         24        INIT_FCALL                                               'date'
         25        SEND_VAL                                                 'Y-m-d'
         26        INIT_FCALL                                               'strtotime'
         27        FETCH_DIM_IS                                     ~19     !4, !3
         28        FETCH_DIM_IS                                     ~20     ~19, 'enddate'
         29        COALESCE                                         ~21     ~20
         30        FETCH_DIM_R                                      ~22     !4, !3
         31        FETCH_DIM_R                                      ~23     ~22, 'startdate'
         32        QM_ASSIGN                                        ~21     ~23
         33        CONCAT                                           ~24     ~21, '+%2B+1+day'
         34        SEND_VAL                                                 ~24
         35        DO_ICALL                                         $25     
         36        SEND_VAR                                                 $25
         37        DO_ICALL                                         $26     
         38        IS_NOT_EQUAL                                     ~27     $26, ~18
         39        BOOL                                             ~17     ~27
         40    > > JMPZ                                                     ~17, ->51
   59    41    >   ISSET_ISEMPTY_DIM_OBJ                         0          !4, !3
         42      > JMPZ                                                     ~28, ->44
   60    43    >   UNSET_DIM                                                !4, !3
   62    44    >   ASSIGN_DIM                                               !4, !3
         45        OP_DATA                                                  !2
   63    46        FETCH_DIM_W                                      $31     !4, !3
         47        MAKE_REF                                         $32     $31
         48        FETCH_DIM_W                                      $30     !1
         49        ASSIGN_REF                                               $30, $32
   56    50      > JMP                                                      ->55
   65    51    >   FETCH_DIM_R                                      ~36     !2, 'startdate'
         52        FETCH_DIM_W                                      $34     !4, !3
         53        ASSIGN_DIM                                               $34, 'enddate'
         54        OP_DATA                                                  ~36
   50    55    > > JMP                                                      ->8
         56    >   FE_FREE                                                  $9
   68    57        INIT_FCALL                                               'var_export'
         58        SEND_VAR                                                 !1
         59        DO_ICALL                                                 
         60      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SsuHr
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_DIM_R                                      ~2      !0, 'startdate'
          3        FETCH_DIM_R                                      ~3      !1, 'startdate'
          4        SPACESHIP                                        ~4      ~2, ~3
          5      > RETURN                                                   ~4
          6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.8 ms | 1019 KiB | 18 Q