3v4l.org

run code in 300+ PHP versions simultaneously
<?php $season_data = [ 'Paul' => [ 'Season' => [2014, 2015, 2016] ], 'John' => [ 'Season' => [2012] ] ]; $appearance_data = [ 'Paul' => [ 'Appearance'=> [ 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2015, 2015, 2015 ] ], 'John' => [ 'Appearance' => [ 2012, 2012, 2012, 2012 ] ] ]; foreach ($season_data as $person => $data) { $defaults = array_fill_keys($data['Season'], 0); $result[$person]['SeasonCounts'] = array_replace( $defaults, array_intersect_key( array_count_values($appearance_data[$person]['Appearance']), $defaults ) ); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/KIseX
function name:  (null)
number of ops:  33
compiled vars:  !0 = $season_data, !1 = $appearance_data, !2 = $data, !3 = $person, !4 = $defaults, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   24     2      > FE_RESET_R                                       $8      !0, ->28
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->28
          4    >   ASSIGN                                                   !3, ~9
   25     5        INIT_FCALL                                               'array_fill_keys'
          6        FETCH_DIM_R                                      ~11     !2, 'Season'
          7        SEND_VAL                                                 ~11
          8        SEND_VAL                                                 0
          9        DO_ICALL                                         $12     
         10        ASSIGN                                                   !4, $12
   26    11        INIT_FCALL                                               'array_replace'
   27    12        SEND_VAR                                                 !4
   28    13        INIT_FCALL                                               'array_intersect_key'
   29    14        INIT_FCALL                                               'array_count_values'
         15        FETCH_DIM_R                                      ~16     !1, !3
         16        FETCH_DIM_R                                      ~17     ~16, 'Appearance'
         17        SEND_VAL                                                 ~17
         18        DO_ICALL                                         $18     
         19        SEND_VAR                                                 $18
   30    20        SEND_VAR                                                 !4
   28    21        DO_ICALL                                         $19     
   30    22        SEND_VAR                                                 $19
   26    23        DO_ICALL                                         $20     
         24        FETCH_DIM_W                                      $14     !5, !3
         25        ASSIGN_DIM                                               $14, 'SeasonCounts'
   30    26        OP_DATA                                                  $20
   24    27      > JMP                                                      ->3
         28    >   FE_FREE                                                  $8
   34    29        INIT_FCALL                                               'var_export'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.72 ms | 1003 KiB | 18 Q