3v4l.org

run code in 500+ PHP versions simultaneously
<?php $events = [ [ 'date' => '1st June', 'events' => [ [ 'location' => 'Venue A', 'name' => 'Pete', 'time' => '4.00pm' ], [ 'location' => 'Venue A', 'name' => 'John', 'time' => '4.30pm' ], [ 'location' => 'Venue B', 'name' => 'Chris', 'time' => '7.30pm' ], [ 'location' => 'Venue A', 'name' => 'Mark', 'time' => '8.00pm' ] ] ], [ 'date' => '2nd June', 'events' => [ [ 'location' => 'Venue B', 'name' => 'Fred', 'time' => '5.00pm' ], [ 'location' => 'Venue C', 'name' => 'Boris', 'time' => '6.00pm' ], [ 'location' => 'Venue A', 'name' => 'Rupert', 'time' => '7.00pm' ], [ 'location' => 'Venue A', 'name' => 'Davis', 'time' => '9.00pm' ] ] ] ]; $resultEvents = []; foreach ($events as ['date' => $date, 'events' => $dayEvents]) { $resultDayEvents = ['date' => $date, 'events' => []]; foreach ($dayEvents as ['location' => $location, 'name' => $name, 'time' => $time]) { $attendee = ['name' => $name, 'time' => $time]; if ($location === ($previousLocation ?? null)) { $resultDayEvents['events'][array_key_last($resultDayEvents['events'])]['attendees'][] = $attendee; } else { $resultDayEvents['events'][] = ['location' => $location, 'attendees' => [$attendee]]; } $previousLocation = $location; } $resultEvents[] = $resultDayEvents; } print_r($resultEvents);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 50
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 50
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 46
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 46
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 46
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
filename:       /in/bC4LK
function name:  (null)
number of ops:  55
compiled vars:  !0 = $events, !1 = $resultEvents, !2 = $date, !3 = $dayEvents, !4 = $resultDayEvents, !5 = $location, !6 = $name, !7 = $time, !8 = $attendee, !9 = $previousLocation
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   56     1        ASSIGN                                                       !1, <array>
   58     2      > FE_RESET_R                                           $12     !0, ->50
          3    > > FE_FETCH_R                                                   $12, $13, ->50
          4    >   FETCH_LIST_R                                         $14     $13, 'date'
          5        ASSIGN                                                       !2, $14
          6        FETCH_LIST_R                                         $16     $13, 'events'
          7        ASSIGN                                                       !3, $16
          8        FREE                                                         $13
   59     9        INIT_ARRAY                                           ~18     !2, 'date'
         10        ADD_ARRAY_ELEMENT                                    ~18     <array>, 'events'
         11        ASSIGN                                                       !4, ~18
   61    12      > FE_RESET_R                                           $20     !3, ->46
         13    > > FE_FETCH_R                                                   $20, $21, ->46
         14    >   FETCH_LIST_R                                         $22     $21, 'location'
         15        ASSIGN                                                       !5, $22
         16        FETCH_LIST_R                                         $24     $21, 'name'
         17        ASSIGN                                                       !6, $24
         18        FETCH_LIST_R                                         $26     $21, 'time'
         19        ASSIGN                                                       !7, $26
         20        FREE                                                         $21
   62    21        INIT_ARRAY                                           ~28     !6, 'name'
         22        ADD_ARRAY_ELEMENT                                    ~28     !7, 'time'
         23        ASSIGN                                                       !8, ~28
   63    24        COALESCE                                             ~30     !9
         25        QM_ASSIGN                                            ~30     null
         26        IS_IDENTICAL                                                 !5, ~30
         27      > JMPZ                                                         ~31, ->38
   64    28    >   INIT_FCALL                                                   'array_key_last'
         29        FETCH_DIM_R                                          ~33     !4, 'events'
         30        SEND_VAL                                                     ~33
         31        DO_ICALL                                             $34     
         32        FETCH_DIM_W                                          $32     !4, 'events'
         33        FETCH_DIM_W                                          $35     $32, $34
         34        FETCH_DIM_W                                          $36     $35, 'attendees'
         35        ASSIGN_DIM                                                   $36
         36        OP_DATA                                                      !8
   63    37      > JMP                                                          ->44
   66    38    >   INIT_ARRAY                                           ~40     !5, 'location'
         39        INIT_ARRAY                                           ~41     !8
         40        ADD_ARRAY_ELEMENT                                    ~40     ~41, 'attendees'
         41        FETCH_DIM_W                                          $38     !4, 'events'
         42        ASSIGN_DIM                                                   $38
         43        OP_DATA                                                      ~40
   68    44    >   ASSIGN                                                       !9, !5
   61    45      > JMP                                                          ->13
         46    >   FE_FREE                                                      $20
   71    47        ASSIGN_DIM                                                   !1
         48        OP_DATA                                                      !4
   58    49      > JMP                                                          ->3
         50    >   FE_FREE                                                      $12
   74    51        INIT_FCALL                                                   'print_r'
         52        SEND_VAR                                                     !1
         53        DO_ICALL                                                     
         54      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
126.35 ms | 484 KiB | 9 Q