3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 'history' => [ 'id' => 23452435, 'legend' => [ ['player' => 'me', 'turn' => 1, 'card' => ['name' => 'foo']], ['player' => 'me', 'turn' => 1, 'card' => ['name' => 'bar']], ['player' => 'opponent', 'turn' => 1, 'card' => ['name' => 'derp']], ['player' => 'opponent', 'turn' => 2, 'card' => ['name' => 'hoo']], ], ] ]; $historyByTurns = array(); foreach ($arr['history'] as $historyItem) { foreach ($historyItem['legend'] as $legendItem) { $turn = $legendItem['turn']; $player = $legendItem['player']; if (!array_key_exists($turn, $historyByTurns)) { $historyByTurns[$turn] = array(); } if (!array_key_exists($player, $historyByTurns[$turn])) { $historyByTurns[$turn][$player] = array(); } foreach ($legendItem as $card) { $historyByTurns[$turn][$player][] = $card['name']; } } } var_export($historyByTurns);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 36
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 36
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 34
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 32
Branch analysis from position: 24
Branch analysis from position: 17
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/kH0BS
function name:  (null)
number of ops:  41
compiled vars:  !0 = $arr, !1 = $historyByTurns, !2 = $historyItem, !3 = $legendItem, !4 = $turn, !5 = $player, !6 = $card
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   16     2        FETCH_DIM_R                                      ~9      !0, 'history'
          3      > FE_RESET_R                                       $10     ~9, ->36
          4    > > FE_FETCH_R                                               $10, !2, ->36
   17     5    >   FETCH_DIM_R                                      ~11     !2, 'legend'
          6      > FE_RESET_R                                       $12     ~11, ->34
          7    > > FE_FETCH_R                                               $12, !3, ->34
   18     8    >   FETCH_DIM_R                                      ~13     !3, 'turn'
          9        ASSIGN                                                   !4, ~13
   19    10        FETCH_DIM_R                                      ~15     !3, 'player'
         11        ASSIGN                                                   !5, ~15
   20    12        ARRAY_KEY_EXISTS                                 ~17     !4, !1
         13        BOOL_NOT                                         ~18     ~17
         14      > JMPZ                                                     ~18, ->17
   21    15    >   ASSIGN_DIM                                               !1, !4
         16        OP_DATA                                                  <array>
   23    17    >   FETCH_DIM_R                                      ~20     !1, !4
         18        ARRAY_KEY_EXISTS                                 ~21     !5, ~20
         19        BOOL_NOT                                         ~22     ~21
         20      > JMPZ                                                     ~22, ->24
   24    21    >   FETCH_DIM_W                                      $23     !1, !4
         22        ASSIGN_DIM                                               $23, !5
         23        OP_DATA                                                  <array>
   26    24    > > FE_RESET_R                                       $25     !3, ->32
         25    > > FE_FETCH_R                                               $25, !6, ->32
   27    26    >   FETCH_DIM_R                                      ~29     !6, 'name'
         27        FETCH_DIM_W                                      $26     !1, !4
         28        FETCH_DIM_W                                      $27     $26, !5
         29        ASSIGN_DIM                                               $27
         30        OP_DATA                                                  ~29
   26    31      > JMP                                                      ->25
         32    >   FE_FREE                                                  $25
   17    33      > JMP                                                      ->7
         34    >   FE_FREE                                                  $12
   16    35      > JMP                                                      ->4
         36    >   FE_FREE                                                  $10
   31    37        INIT_FCALL                                               'var_export'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                                 
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.84 ms | 1015 KiB | 14 Q