3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array( 0 => array( 2 => array( "type" => 1, "score" => 10, ), ), 1 => array( 2 => array( "type" => 2, "score" => 5, ), ), 2 => array( 2 => array( "type" => 3, "score" => 4, ), ), 3 => array( 2 => array( "type" => 4, "score" => 60, ), ), 4 => array( 1 => array( "type" => 1, "score" => 5, ), ), ); $array2 = array(0 => 2, 1 => 1); $array3 = array( 2 => array( "score" => 79 ), 1 => array( "score" => 5 ), ); foreach( $array1 as $array1x ){ $key=key($array1x); if( in_array($key, $array2) ){ $this_score = $array1x[$key]['score']; $cum_score = isset($newarray[$key]['score']) ? $newarray[$key]['score'] : 0; $newarray[$key]['score'] = $cum_score + $this_score; } } print_r($newarray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 31
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 31
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 30
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 24
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/iKU8j
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3, !3 = $array1x, !4 = $key, !5 = $this_score, !6 = $cum_score, !7 = $newarray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1        ASSIGN                                                   !1, <array>
   38     2        ASSIGN                                                   !2, <array>
   47     3      > FE_RESET_R                                       $11     !0, ->31
          4    > > FE_FETCH_R                                               $11, !3, ->31
   48     5    >   INIT_FCALL                                               'key'
          6        SEND_VAR                                                 !3
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !4, $12
   49     9        INIT_FCALL                                               'in_array'
         10        SEND_VAR                                                 !4
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $14     
         13      > JMPZ                                                     $14, ->30
   50    14    >   FETCH_DIM_R                                      ~15     !3, !4
         15        FETCH_DIM_R                                      ~16     ~15, 'score'
         16        ASSIGN                                                   !5, ~16
   51    17        FETCH_DIM_IS                                     ~18     !7, !4
         18        ISSET_ISEMPTY_DIM_OBJ                         0          ~18, 'score'
         19      > JMPZ                                                     ~19, ->24
         20    >   FETCH_DIM_R                                      ~20     !7, !4
         21        FETCH_DIM_R                                      ~21     ~20, 'score'
         22        QM_ASSIGN                                        ~22     ~21
         23      > JMP                                                      ->25
         24    >   QM_ASSIGN                                        ~22     0
         25    >   ASSIGN                                                   !6, ~22
   52    26        ADD                                              ~26     !6, !5
         27        FETCH_DIM_W                                      $24     !7, !4
         28        ASSIGN_DIM                                               $24, 'score'
         29        OP_DATA                                                  ~26
   47    30    > > JMP                                                      ->4
         31    >   FE_FREE                                                  $11
   55    32        INIT_FCALL                                               'print_r'
         33        SEND_VAR                                                 !7
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.11 ms | 1400 KiB | 19 Q