3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ 0 => [ 'period' => '2017/2018', 'product' => 'AM', 'quantity_1' => 20, 'quantity' => 25, ], 1 => [ 'period' => '2018/2019', 'product' => 'AM', 'quantity_1' => 12, 'quantity' => 19, ], 2 => [ 'period' => '2017/2018', 'product' => 'DC', 'quantity_1' => 20, 'quantity' => 25, ], 3 => [ 'period' => '2018/2019', 'product' => 'DC', 'quantity_1' => 8, 'quantity' => 10, ] ]; $temp = []; foreach ($a as $x){ $temp[$x['product']][$x['period']] = $x; } print_r($temp); $result = []; foreach ($temp as $key => $res){ $result[] = [ 'product' => $key, 'quantity_1' => $res['2018/2019']['quantity_1'] / $res['2017/2018']['quantity_1'], 'quantity_2' => $res['2018/2019']['quantity'] / $res['2017/2018']['quantity'], ]; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 34
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 34
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 10
filename:       /in/aGU5D
function name:  (null)
number of ops:  39
compiled vars:  !0 = $a, !1 = $temp, !2 = $x, !3 = $result, !4 = $res, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, <array>
   30     2      > FE_RESET_R                                       $8      !0, ->10
          3    > > FE_FETCH_R                                               $8, !2, ->10
   31     4    >   FETCH_DIM_R                                      ~9      !2, 'product'
          5        FETCH_DIM_R                                      ~11     !2, 'period'
          6        FETCH_DIM_W                                      $10     !1, ~9
          7        ASSIGN_DIM                                               $10, ~11
          8        OP_DATA                                                  !2
   30     9      > JMP                                                      ->3
         10    >   FE_FREE                                                  $8
   33    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   35    14        ASSIGN                                                   !3, <array>
   36    15      > FE_RESET_R                                       $15     !1, ->34
         16    > > FE_FETCH_R                                       ~16     $15, !4, ->34
         17    >   ASSIGN                                                   !5, ~16
   38    18        INIT_ARRAY                                       ~19     !5, 'product'
   39    19        FETCH_DIM_R                                      ~20     !4, '2018%2F2019'
         20        FETCH_DIM_R                                      ~21     ~20, 'quantity_1'
         21        FETCH_DIM_R                                      ~22     !4, '2017%2F2018'
         22        FETCH_DIM_R                                      ~23     ~22, 'quantity_1'
         23        DIV                                              ~24     ~21, ~23
         24        ADD_ARRAY_ELEMENT                                ~19     ~24, 'quantity_1'
   40    25        FETCH_DIM_R                                      ~25     !4, '2018%2F2019'
         26        FETCH_DIM_R                                      ~26     ~25, 'quantity'
         27        FETCH_DIM_R                                      ~27     !4, '2017%2F2018'
         28        FETCH_DIM_R                                      ~28     ~27, 'quantity'
         29        DIV                                              ~29     ~26, ~28
         30        ADD_ARRAY_ELEMENT                                ~19     ~29, 'quantity_2'
   37    31        ASSIGN_DIM                                               !3
   40    32        OP_DATA                                                  ~19
   36    33      > JMP                                                      ->16
         34    >   FE_FREE                                                  $15
   44    35        INIT_FCALL                                               'print_r'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
297.06 ms | 1010 KiB | 14 Q