3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( array('num'=>5,'period'=>3), array('num'=>10,'period'=>3), array('num'=>15,'period'=>9) ); $temp = array(); foreach($arr as $item) { list($n, $p) = array_values($item); $temp[$p] = array_key_exists($p, $temp) ? $temp[$p]+$n : $n; } print_r($temp); $arr = array(); foreach($temp as $p => $n) $arr[] = array('num'=>$n, 'period'=>$p); print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
Branch analysis from position: 22
filename:       /in/WfEOA
function name:  (null)
number of ops:  40
compiled vars:  !0 = $arr, !1 = $temp, !2 = $item, !3 = $n, !4 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $7      !0, ->22
          3    > > FE_FETCH_R                                               $7, !2, ->22
   13     4    >   INIT_FCALL                                               'array_values'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $8      
          7        FETCH_LIST_R                                     $9      $8, 0
          8        ASSIGN                                                   !3, $9
          9        FETCH_LIST_R                                     $11     $8, 1
         10        ASSIGN                                                   !4, $11
         11        FREE                                                     $8
   14    12        ARRAY_KEY_EXISTS                                         !4, !1
         13      > JMPZ                                                     ~14, ->18
         14    >   FETCH_DIM_R                                      ~15     !1, !4
         15        ADD                                              ~16     ~15, !3
         16        QM_ASSIGN                                        ~17     ~16
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~17     !3
         19    >   ASSIGN_DIM                                               !1, !4
         20        OP_DATA                                                  ~17
   12    21      > JMP                                                      ->3
         22    >   FE_FREE                                                  $7
   16    23        INIT_FCALL                                               'print_r'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                                 
   17    26        ASSIGN                                                   !0, <array>
   18    27      > FE_RESET_R                                       $20     !1, ->35
         28    > > FE_FETCH_R                                       ~21     $20, !3, ->35
         29    >   ASSIGN                                                   !4, ~21
   19    30        INIT_ARRAY                                       ~24     !3, 'num'
         31        ADD_ARRAY_ELEMENT                                ~24     !4, 'period'
         32        ASSIGN_DIM                                               !0
         33        OP_DATA                                                  ~24
   18    34      > JMP                                                      ->28
         35    >   FE_FREE                                                  $20
   21    36        INIT_FCALL                                               'print_r'
         37        SEND_VAR                                                 !0
         38        DO_ICALL                                                 
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.94 ms | 1400 KiB | 17 Q