3v4l.org

run code in 300+ PHP versions simultaneously
<?php # The events array. $events = [ [ "title" => "Title 1", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2017-05-25" ], [ "title" => "Title 2", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-05-25" ], [ "title" => "Title 3", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-05-27" ], [ "title" => "Title 3", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2018-07-15" ], [ "title" => "Title 4", "start_time" => "09:00", "end_time" => "17:00", "start_date" => "2019-01-02" ] ]; # Create an array to store the data. $grouped = []; # Iterate over every event. foreach ($events as $event) { # Format and save the date as 'Month Year'. $monthYear = date("F Y", strtotime($event["start_date"])); # Define the key of the object as as an array, if not already defined. $grouped[$monthYear] = $grouped[$monthYear] ?? []; # Insert the title to the array corresponding to the formatted date. $grouped[$monthYear][] = $event["title"]; } # Iterate over every key - value. foreach ($grouped as $key => $value) { # Print the 'Month Year' key. echo $key . "\n"; # Iterate over every title and print it. foreach ($value as $title) echo "- $title\n"; # Separate each group with an empty line. echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 39
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 39
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 36
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
Branch analysis from position: 23
filename:       /in/e9863
function name:  (null)
number of ops:  41
compiled vars:  !0 = $events, !1 = $grouped, !2 = $event, !3 = $monthYear, !4 = $value, !5 = $key, !6 = $title
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   34     1        ASSIGN                                                   !1, <array>
   37     2      > FE_RESET_R                                       $9      !0, ->23
          3    > > FE_FETCH_R                                               $9, !2, ->23
   39     4    >   INIT_FCALL                                               'date'
          5        SEND_VAL                                                 'F+Y'
          6        INIT_FCALL                                               'strtotime'
          7        FETCH_DIM_R                                      ~10     !2, 'start_date'
          8        SEND_VAL                                                 ~10
          9        DO_ICALL                                         $11     
         10        SEND_VAR                                                 $11
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !3, $12
   42    13        FETCH_DIM_IS                                     ~15     !1, !3
         14        COALESCE                                         ~16     ~15
         15        QM_ASSIGN                                        ~16     <array>
         16        ASSIGN_DIM                                               !1, !3
         17        OP_DATA                                                  ~16
   45    18        FETCH_DIM_R                                      ~19     !2, 'title'
         19        FETCH_DIM_W                                      $17     !1, !3
         20        ASSIGN_DIM                                               $17
         21        OP_DATA                                                  ~19
   37    22      > JMP                                                      ->3
         23    >   FE_FREE                                                  $9
   49    24      > FE_RESET_R                                       $20     !1, ->39
         25    > > FE_FETCH_R                                       ~21     $20, !4, ->39
         26    >   ASSIGN                                                   !5, ~21
   51    27        CONCAT                                           ~23     !5, '%0A'
         28        ECHO                                                     ~23
   54    29      > FE_RESET_R                                       $24     !4, ->36
         30    > > FE_FETCH_R                                               $24, !6, ->36
         31    >   ROPE_INIT                                     3  ~26     '-+'
         32        ROPE_ADD                                      1  ~26     ~26, !6
         33        ROPE_END                                      2  ~25     ~26, '%0A'
         34        ECHO                                                     ~25
         35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $24
   57    37        ECHO                                                     '%0A'
   49    38      > JMP                                                      ->25
         39    >   FE_FREE                                                  $20
   58    40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.98 ms | 1016 KiB | 15 Q