3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "2022-10-30" => ['▶'], "2022-10-31" => ['▶'], "2022-11-07" => ['▶'], "2022-11-09" => ['▶'] ]; $result = []; foreach ($array as $key => $value) { $ym = substr($key, 0, 7); if (!isset($lookup[$ym]) || $lookup[$ym] < $key) { $result[$key] = $value; if (isset($lookup[$ym])) { unset($result[$lookup[$ym]]); } $lookup[$ym] = $key; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 27
Branch analysis from position: 4
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 26
Branch analysis from position: 17
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/WcTd7
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $result, !2 = $value, !3 = $key, !4 = $ym, !5 = $lookup
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $8      !0, ->27
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->27
          4    >   ASSIGN                                                   !3, ~9
   12     5        INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !3
          7        SEND_VAL                                                 0
          8        SEND_VAL                                                 7
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !4, $11
   13    11        ISSET_ISEMPTY_DIM_OBJ                         0  ~13     !5, !4
         12        BOOL_NOT                                         ~14     ~13
         13      > JMPNZ_EX                                         ~14     ~14, ->17
         14    >   FETCH_DIM_R                                      ~15     !5, !4
         15        IS_SMALLER                                       ~16     ~15, !3
         16        BOOL                                             ~14     ~16
         17    > > JMPZ                                                     ~14, ->26
   14    18    >   ASSIGN_DIM                                               !1, !3
         19        OP_DATA                                                  !2
   15    20        ISSET_ISEMPTY_DIM_OBJ                         0          !5, !4
         21      > JMPZ                                                     ~18, ->24
   16    22    >   FETCH_DIM_R                                      ~19     !5, !4
         23        UNSET_DIM                                                !1, ~19
   18    24    >   ASSIGN_DIM                                               !5, !4
         25        OP_DATA                                                  !3
   11    26    > > JMP                                                      ->3
         27    >   FE_FREE                                                  $8
   21    28        INIT_FCALL                                               'var_export'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.65 ms | 1400 KiB | 17 Q