3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = Array ( 0 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '1000', ), 1 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '7777', ), 2 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '7777', ), 3 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '4000', ), 4 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '4000', ), 5 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '5000', ), 6 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '6000', ), 7 => Array ( 'name' => 'John Doe', 'age' => '36', 'code' => '437', 'group' => '6000', ), ); $names = array_column($array, "name"); $groups = array_column($array, "group"); foreach(array_unique($names) as $name){ $intersects = array_intersect_key($array, array_intersect($names, [$name])); $new[$name] = ["name" => $name, "age" => end($intersects)["age"]]; foreach(array_unique($groups) as $group){ $intersects = array_intersect_key($array, array_intersect($groups, [$group])); foreach($intersects as $int){ $temp = array_diff($int, ["name" => $new[$name]["name"], "age" => $new[$name]["age"]]); if($temp["group"] == "1000" || $temp["group"] == "7777"){ $new[$name][$group][] = $temp; }else{ $new[$name]["others"][] = $temp; } } } } var_dump($new);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 83
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 83
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 81
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 81
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 50, Position 2 = 79
Branch analysis from position: 50
2 jumps found. (Code = 78) Position 1 = 51, Position 2 = 79
Branch analysis from position: 51
2 jumps found. (Code = 47) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 74
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 68
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 79
Branch analysis from position: 81
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 81
Branch analysis from position: 83
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 83
filename:       /in/jCKk7
function name:  (null)
number of ops:  88
compiled vars:  !0 = $array, !1 = $names, !2 = $groups, !3 = $name, !4 = $intersects, !5 = $new, !6 = $group, !7 = $int, !8 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   69     1        INIT_FCALL                                               'array_column'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'name'
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !1, $10
   70     6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'group'
          9        DO_ICALL                                         $12     
         10        ASSIGN                                                   !2, $12
   72    11        INIT_FCALL                                               'array_unique'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $14     
         14      > FE_RESET_R                                       $15     $14, ->83
         15    > > FE_FETCH_R                                               $15, !3, ->83
   73    16    >   INIT_FCALL                                               'array_intersect_key'
         17        SEND_VAR                                                 !0
         18        INIT_FCALL                                               'array_intersect'
         19        SEND_VAR                                                 !1
         20        INIT_ARRAY                                       ~16     !3
         21        SEND_VAL                                                 ~16
         22        DO_ICALL                                         $17     
         23        SEND_VAR                                                 $17
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !4, $18
   74    26        INIT_ARRAY                                       ~21     !3, 'name'
         27        INIT_FCALL                                               'end'
         28        SEND_REF                                                 !4
         29        DO_ICALL                                         $22     
         30        FETCH_DIM_R                                      ~23     $22, 'age'
         31        ADD_ARRAY_ELEMENT                                ~21     ~23, 'age'
         32        ASSIGN_DIM                                               !5, !3
         33        OP_DATA                                                  ~21
   75    34        INIT_FCALL                                               'array_unique'
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $24     
         37      > FE_RESET_R                                       $25     $24, ->81
         38    > > FE_FETCH_R                                               $25, !6, ->81
   76    39    >   INIT_FCALL                                               'array_intersect_key'
         40        SEND_VAR                                                 !0
         41        INIT_FCALL                                               'array_intersect'
         42        SEND_VAR                                                 !2
         43        INIT_ARRAY                                       ~26     !6
         44        SEND_VAL                                                 ~26
         45        DO_ICALL                                         $27     
         46        SEND_VAR                                                 $27
         47        DO_ICALL                                         $28     
         48        ASSIGN                                                   !4, $28
   77    49      > FE_RESET_R                                       $30     !4, ->79
         50    > > FE_FETCH_R                                               $30, !7, ->79
   78    51    >   INIT_FCALL                                               'array_diff'
         52        SEND_VAR                                                 !7
         53        FETCH_DIM_R                                      ~31     !5, !3
         54        FETCH_DIM_R                                      ~32     ~31, 'name'
         55        INIT_ARRAY                                       ~33     ~32, 'name'
         56        FETCH_DIM_R                                      ~34     !5, !3
         57        FETCH_DIM_R                                      ~35     ~34, 'age'
         58        ADD_ARRAY_ELEMENT                                ~33     ~35, 'age'
         59        SEND_VAL                                                 ~33
         60        DO_ICALL                                         $36     
         61        ASSIGN                                                   !8, $36
   79    62        FETCH_DIM_R                                      ~38     !8, 'group'
         63        IS_EQUAL                                         ~39     ~38, '1000'
         64      > JMPNZ_EX                                         ~39     ~39, ->68
         65    >   FETCH_DIM_R                                      ~40     !8, 'group'
         66        IS_EQUAL                                         ~41     ~40, '7777'
         67        BOOL                                             ~39     ~41
         68    > > JMPZ                                                     ~39, ->74
   80    69    >   FETCH_DIM_W                                      $42     !5, !3
         70        FETCH_DIM_W                                      $43     $42, !6
         71        ASSIGN_DIM                                               $43
         72        OP_DATA                                                  !8
         73      > JMP                                                      ->78
   82    74    >   FETCH_DIM_W                                      $45     !5, !3
         75        FETCH_DIM_W                                      $46     $45, 'others'
         76        ASSIGN_DIM                                               $46
         77        OP_DATA                                                  !8
   77    78    > > JMP                                                      ->50
         79    >   FE_FREE                                                  $30
   75    80      > JMP                                                      ->38
         81    >   FE_FREE                                                  $25
   72    82      > JMP                                                      ->15
         83    >   FE_FREE                                                  $15
   87    84        INIT_FCALL                                               'var_dump'
         85        SEND_VAR                                                 !5
         86        DO_ICALL                                                 
         87      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.66 ms | 1404 KiB | 27 Q