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_count_values( array_intersect( $appearance_data[$person]['Appearance'], $data['Season'] ) ) ); } 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
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/GNEcZ
function name:  (null)
number of ops:  34
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, ->29
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->29
          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_count_values'
   29    14        INIT_FCALL                                               'array_intersect'
   30    15        FETCH_DIM_R                                      ~16     !1, !3
         16        FETCH_DIM_R                                      ~17     ~16, 'Appearance'
         17        SEND_VAL                                                 ~17
   31    18        FETCH_DIM_R                                      ~18     !2, 'Season'
         19        SEND_VAL                                                 ~18
   29    20        DO_ICALL                                         $19     
   31    21        SEND_VAR                                                 $19
   28    22        DO_ICALL                                         $20     
   31    23        SEND_VAR                                                 $20
   26    24        DO_ICALL                                         $21     
         25        FETCH_DIM_W                                      $14     !5, !3
         26        ASSIGN_DIM                                               $14, 'SeasonCounts'
   31    27        OP_DATA                                                  $21
   24    28      > JMP                                                      ->3
         29    >   FE_FREE                                                  $8
   36    30        INIT_FCALL                                               'var_export'
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
290.01 ms | 1003 KiB | 18 Q