3v4l.org

run code in 300+ PHP versions simultaneously
<?php $team = [ ['id' => 1, 'name' => 'Team A'], ['id' => 2, 'name' => 'Team B'], ['id' => 3, 'name' => 'Team C'], ]; $people = [ ['id' => 1, 'name' => 'Mark Hamill', 'team' => 1], ['id' => 2, 'name' => 'Nicolas Cage', 'team' => 2], ['id' => 3, 'name' => 'Tom Cruise', 'team' => 3], ['id' => 4, 'name' => 'Tom Hanks', 'team' => 1], ['id' => 5, 'name' => 'Brad Pitt', 'team' => 2], ['id' => 6, 'name' => 'Paul Smith', 'team' => 3], ['id' => 7, 'name' => 'Matt Daemon', 'team' => 1], ['id' => 8, 'name' => 'Robert Redford', 'team' => 2], ]; $teampeople = array_column($people, "team"); Foreach($team as &$t){ $t['members'] = array_values(array_intersect_key($people, array_intersect($teampeople, [$t['id']]))); } Var_dump($team);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 126) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/kmvuR
function name:  (null)
number of ops:  30
compiled vars:  !0 = $team, !1 = $people, !2 = $teampeople, !3 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   19     2        INIT_FCALL                                               'array_column'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 'team'
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
   21     7      > FE_RESET_RW                                      $8      !0, ->25
          8    > > FE_FETCH_RW                                              $8, !3, ->25
   22     9    >   INIT_FCALL                                               'array_values'
         10        INIT_FCALL                                               'array_intersect_key'
         11        SEND_VAR                                                 !1
         12        INIT_FCALL                                               'array_intersect'
         13        SEND_VAR                                                 !2
         14        FETCH_DIM_R                                      ~10     !3, 'id'
         15        INIT_ARRAY                                       ~11     ~10
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $12     
         18        SEND_VAR                                                 $12
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        DO_ICALL                                         $14     
         22        ASSIGN_DIM                                               !3, 'members'
         23        OP_DATA                                                  $14
   21    24      > JMP                                                      ->8
         25    >   FE_FREE                                                  $8
   24    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.29 ms | 1401 KiB | 23 Q