3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ [ 'TYPE' => 'Answer', 'PARTY_ID' => 115, 'PARENT_USER_CONTENT_ID' => 114 ], [ 'TYPE' => 'Question', 'PARTY_ID' => 112, 'PARENT_USER_CONTENT_ID' => '' ], [ 'TYPE' => 'Question', 'PARTY_ID' => 113, 'PARENT_USER_CONTENT_ID' => '' ], [ 'TYPE' => 'Answer', 'PARTY_ID' => 116, 'PARENT_USER_CONTENT_ID' => 113 ], [ 'TYPE' => 'Question', 'PARTY_ID' => 114, 'PARENT_USER_CONTENT_ID' => '' ], [ 'TYPE' => 'Answer', 'PARTY_ID' => 117, 'PARENT_USER_CONTENT_ID' => 112 ] ]; $indexed = array_combine(array_column($arr, 'PARTY_ID'), $arr); $answers = array_flip(array_filter(array_column($arr, 'PARENT_USER_CONTENT_ID', 'PARTY_ID'))); foreach ($answers as $parentPartyId => $childPartyId) { $result[] = array_merge($indexed[$parentPartyId], [ 'ANSWER' => $indexed[$childPartyId]]); } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 35
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/QrAJI
function name:  (null)
number of ops:  40
compiled vars:  !0 = $arr, !1 = $indexed, !2 = $answers, !3 = $childPartyId, !4 = $parentPartyId, !5 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        INIT_FCALL                                                   'array_combine'
          2        INIT_FCALL                                                   'array_column'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'PARTY_ID'
          5        DO_ICALL                                             $7      
          6        SEND_VAR                                                     $7
          7        SEND_VAR                                                     !0
          8        DO_ICALL                                             $8      
          9        ASSIGN                                                       !1, $8
   13    10        INIT_FCALL                                                   'array_flip'
         11        INIT_FCALL                                                   'array_filter'
         12        INIT_FCALL                                                   'array_column'
         13        SEND_VAR                                                     !0
         14        SEND_VAL                                                     'PARENT_USER_CONTENT_ID'
         15        SEND_VAL                                                     'PARTY_ID'
         16        DO_ICALL                                             $10     
         17        SEND_VAR                                                     $10
         18        DO_ICALL                                             $11     
         19        SEND_VAR                                                     $11
         20        DO_ICALL                                             $12     
         21        ASSIGN                                                       !2, $12
   15    22      > FE_RESET_R                                           $14     !2, ->35
         23    > > FE_FETCH_R                                           ~15     $14, !3, ->35
         24    >   ASSIGN                                                       !4, ~15
   16    25        INIT_FCALL                                                   'array_merge'
         26        FETCH_DIM_R                                          ~18     !1, !4
         27        SEND_VAL                                                     ~18
         28        FETCH_DIM_R                                          ~19     !1, !3
         29        INIT_ARRAY                                           ~20     ~19, 'ANSWER'
         30        SEND_VAL                                                     ~20
         31        DO_ICALL                                             $21     
         32        ASSIGN_DIM                                                   !5
         33        OP_DATA                                                      $21
   15    34      > JMP                                                          ->23
         35    >   FE_FREE                                                      $14
   19    36        INIT_FCALL                                                   'print_r'
         37        SEND_VAR                                                     !5
         38        DO_ICALL                                                     
         39      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.13 ms | 2298 KiB | 19 Q