3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "2022-10-30" => ['▶'], "2022-10-31" => ['▶'], "2022-11-09" => ['▶'], "2022-11-07" => ['▶'] ]; $result = []; foreach ($array as $key => $value) { $ym = substr($key, 0, 7); if (!isset($lookup[$ym])) { $result[$key] = $value; $lookup[$ym] = $key; } elseif ($lookup[$ym] < $key) { unset($result[$lookup[$ym]]); $result[$key] = $value; $lookup[$ym] = $key; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/67YBS
function name:  (null)
number of ops:  34
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, ->29
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->29
          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      > JMPZ                                                     ~14, ->19
   14    14    >   ASSIGN_DIM                                               !1, !3
         15        OP_DATA                                                  !2
   15    16        ASSIGN_DIM                                               !5, !4
         17        OP_DATA                                                  !3
         18      > JMP                                                      ->28
   16    19    >   FETCH_DIM_R                                      ~17     !5, !4
         20        IS_SMALLER                                               ~17, !3
         21      > JMPZ                                                     ~18, ->28
   17    22    >   FETCH_DIM_R                                      ~19     !5, !4
         23        UNSET_DIM                                                !1, ~19
   18    24        ASSIGN_DIM                                               !1, !3
         25        OP_DATA                                                  !2
   19    26        ASSIGN_DIM                                               !5, !4
         27        OP_DATA                                                  !3
   11    28    > > JMP                                                      ->3
         29    >   FE_FREE                                                  $8
   22    30        INIT_FCALL                                               'var_export'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.41 ms | 1401 KiB | 17 Q