3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inventory = array ( 0 => array ( 'item' => 'NK', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '11', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '1', 'date' => '2017-10-29', ), ), 'item_no' => '1', ), 1 => array ( 'item' => 'FL', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '7', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '2', 'date' => '2017-10-29', ), ), 'item_no' => '2', ), 2 => array ( 'item' => 'AD', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '5', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '3', 'date' => '2017-10-29', ), ), 'item_no' => '3', ), 3 => array ( 'item' => 'CV', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '4', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '6', 'date' => '2017-10-29', ), ), 'item_no' => '4', ), 4 => array ( 'item' => 'NB', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '12', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '4', 'date' => '2017-10-29', ), ), 'item_no' => '5', ), 5 => array ( 'item' => 'SP', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '4', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '6', 'date' => '2017-10-29', ), ), 'item_no' => '6', ), 6 => array ( 'item' => 'WB', 'item_group' => '5', 'sold' => array ( 0 => array ( 'quantity' => '5', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '2', 'date' => '2017-10-29', ), ), 'item_no' => '7', ), 7 => array ( 'item' => 'wny', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '4', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '6', 'date' => '2017-10-29', ), ), 'item_no' => '8', ), 8 => array ( 'item' => 'bs', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '15', 'date' => '2017-10-28', ), 1 => array ( 'quantity' => '2', 'date' => '2017-10-29', ), ), 'item_no' => '9', ), 9 => array ( 'item' => 'st', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '16', 'date' => '2017-10-29', ), ), 'item_no' => '10', ), 10 => array ( 'item' => 'ayhtdws', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '2', 'date' => '2017-10-29', ), ), 'item_no' => '11', ), 11 => array ( 'item' => 'sif', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '3', 'date' => '2017-10-29', ), ), 'item_no' => '12', ), 12 => array ( 'item' => 'bb', 'item_group' => '12', 'sold' => array ( 0 => array ( 'quantity' => '6', 'date' => '2017-10-29', ), ), 'item_no' => '13', ), ); $new =[]; Foreach($inventory as $sub){ Foreach($sub["sold"] as $sold){ If(!isset($new[$sold["date"]]["date"])) $new[$sold["date"]]["date"] = $sold["date"]; $new[$sold["date"]][$sub["item"]] = $sold["quantity"]; } } $new = array_values($new); Var_dump($new);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 17
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/mGJSX
function name:  (null)
number of ops:  35
compiled vars:  !0 = $inventory, !1 = $new, !2 = $sub, !3 = $sold
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
  233     1        ASSIGN                                                   !1, <array>
  235     2      > FE_RESET_R                                       $6      !0, ->26
          3    > > FE_FETCH_R                                               $6, !2, ->26
  236     4    >   FETCH_DIM_R                                      ~7      !2, 'sold'
          5      > FE_RESET_R                                       $8      ~7, ->24
          6    > > FE_FETCH_R                                               $8, !3, ->24
  237     7    >   FETCH_DIM_R                                      ~9      !3, 'date'
          8        FETCH_DIM_IS                                     ~10     !1, ~9
          9        ISSET_ISEMPTY_DIM_OBJ                         0  ~11     ~10, 'date'
         10        BOOL_NOT                                         ~12     ~11
         11      > JMPZ                                                     ~12, ->17
         12    >   FETCH_DIM_R                                      ~13     !3, 'date'
         13        FETCH_DIM_R                                      ~16     !3, 'date'
         14        FETCH_DIM_W                                      $14     !1, ~13
         15        ASSIGN_DIM                                               $14, 'date'
         16        OP_DATA                                                  ~16
  238    17    >   FETCH_DIM_R                                      ~17     !3, 'date'
         18        FETCH_DIM_R                                      ~19     !2, 'item'
         19        FETCH_DIM_R                                      ~21     !3, 'quantity'
         20        FETCH_DIM_W                                      $18     !1, ~17
         21        ASSIGN_DIM                                               $18, ~19
         22        OP_DATA                                                  ~21
  236    23      > JMP                                                      ->6
         24    >   FE_FREE                                                  $8
  235    25      > JMP                                                      ->3
         26    >   FE_FREE                                                  $6
  241    27        INIT_FCALL                                               'array_values'
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $22     
         30        ASSIGN                                                   !1, $22
  242    31        INIT_FCALL                                               'var_dump'
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.57 ms | 1411 KiB | 17 Q