3v4l.org

run code in 500+ PHP versions simultaneously
<?php $results = [ [ 'id' => '1000', 'name' => 'Nurten', 'pId' => '26', 'anzahl' => '1', 'pName' => 'Fitness-Teller', 'preis' => '12.90', ], [ 'id' => '1001', 'name' => 'Kutscha', 'pId' => '94', 'anzahl' => '1', 'pName' => 'Pizza Parma', 'preis' => '12.90', ], [ 'id' => '1001', 'name' => 'Kutscha', 'pId' => '75', 'anzahl' => '1', 'pName' => 'Pizza Margherita', 'preis' => '6.50', ], ]; $out = []; foreach ($results as $result) { if (!isset($out[$result['id']])) { $out[$result['id']] = array_filter($result, function($key) { return in_array($key, ['id','name']); }, ARRAY_FILTER_USE_KEY); } $out[$result['id']]['products'][] = array_filter($result, function($key) { return in_array($key, ['pId','anzahl','pName','preis']); }, ARRAY_FILTER_USE_KEY); } print_r(array_values($out));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/DTCXH
function name:  (null)
number of ops:  37
compiled vars:  !0 = $results, !1 = $out, !2 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                       !0, <array>
   32     1        ASSIGN                                                       !1, <array>
   33     2      > FE_RESET_R                                           $5      !0, ->29
          3    > > FE_FETCH_R                                                   $5, !2, ->29
   35     4    >   FETCH_DIM_R                                          ~6      !2, 'id'
          5        ISSET_ISEMPTY_DIM_OBJ                             0  ~7      !1, ~6
          6        BOOL_NOT                                             ~8      ~7
          7      > JMPZ                                                         ~8, ->17
   36     8    >   FETCH_DIM_R                                          ~9      !2, 'id'
          9        INIT_FCALL                                                   'array_filter'
         10        SEND_VAR                                                     !2
         11        DECLARE_LAMBDA_FUNCTION                              ~11     [0]
   38    12        SEND_VAL                                                     ~11
         13        SEND_VAL                                                     2
   36    14        DO_ICALL                                             $12     
         15        ASSIGN_DIM                                                   !1, ~9
   38    16        OP_DATA                                                      $12
   41    17    >   FETCH_DIM_R                                          ~13     !2, 'id'
         18        INIT_FCALL                                                   'array_filter'
         19        SEND_VAR                                                     !2
         20        DECLARE_LAMBDA_FUNCTION                              ~17     [1]
   43    21        SEND_VAL                                                     ~17
         22        SEND_VAL                                                     2
   41    23        DO_ICALL                                             $18     
         24        FETCH_DIM_W                                          $14     !1, ~13
         25        FETCH_DIM_W                                          $15     $14, 'products'
         26        ASSIGN_DIM                                                   $15
   43    27        OP_DATA                                                      $18
   33    28      > JMP                                                          ->3
         29    >   FE_FREE                                                      $5
   45    30        INIT_FCALL                                                   'print_r'
         31        INIT_FCALL                                                   'array_values'
         32        SEND_VAR                                                     !1
         33        DO_ICALL                                             $19     
         34        SEND_VAR                                                     $19
         35        DO_ICALL                                                     
         36      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DTCXH
function name:  {closure:/in/DTCXH:36}
number of ops:  4
compiled vars:  !0 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   RECV                                                 !0      
   37     1        IN_ARRAY                                             ~1      !0, <array>
          2      > RETURN                                                       ~1
   38     3*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DTCXH
function name:  {closure:/in/DTCXH:41}
number of ops:  4
compiled vars:  !0 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   41     0  E >   RECV                                                 !0      
   42     1        IN_ARRAY                                             ~1      !0, <array>
          2      > RETURN                                                       ~1
   43     3*     > RETURN                                                       null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.87 ms | 3863 KiB | 16 Q