3v4l.org

run code in 500+ 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 = 28
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 28
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 27
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/iKU8j
function name:  (null)
number of ops:  33
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, ->28
          4    > > FE_FETCH_R                                                   $11, !3, ->28
   48     5    >   INIT_FCALL                                                   'key'
          6        SEND_VAR                                                     !3
          7        DO_ICALL                                             $12     
          8        ASSIGN                                                       !4, $12
   49     9        FRAMELESS_ICALL_2                in_array            ~14     !4, !1
         10      > JMPZ                                                         ~14, ->27
   50    11    >   FETCH_DIM_R                                          ~15     !3, !4
         12        FETCH_DIM_R                                          ~16     ~15, 'score'
         13        ASSIGN                                                       !5, ~16
   51    14        FETCH_DIM_IS                                         ~18     !7, !4
         15        ISSET_ISEMPTY_DIM_OBJ                             0          ~18, 'score'
         16      > JMPZ                                                         ~19, ->21
         17    >   FETCH_DIM_R                                          ~20     !7, !4
         18        FETCH_DIM_R                                          ~21     ~20, 'score'
         19        QM_ASSIGN                                            ~22     ~21
         20      > JMP                                                          ->22
         21    >   QM_ASSIGN                                            ~22     0
         22    >   ASSIGN                                                       !6, ~22
   52    23        ADD                                                  ~26     !6, !5
         24        FETCH_DIM_W                                          $24     !7, !4
         25        ASSIGN_DIM                                                   $24, 'score'
         26        OP_DATA                                                      ~26
   47    27    > > JMP                                                          ->4
         28    >   FE_FREE                                                      $11
   55    29        INIT_FCALL                                                   'print_r'
         30        SEND_VAR                                                     !7
         31        DO_ICALL                                                     
         32      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.17 ms | 2004 KiB | 15 Q