3v4l.org

run code in 300+ PHP versions simultaneously
<?php $item = array ( 0 => array ( 'invoice_id' => '72,', 'item' => 'SN00001' ), 1 => array ( 'invoice_id' => '73,', 'item' => 'SN00002' ), 2 => array ( 'invoice_id' => '73,', 'item' => 'SN00003' ), 3 => array ( 'invoice_id' => '73,', 'item' => 'SN00004' ), 4 => array ( 'invoice_id' => '74,', 'item' => 'SN00005' ), 5 => array ( 'invoice_id' => '74,', 'item' => 'SN00006' ) ); $items = array_map(function ($inv_id) use ($item) { return array('invoice_id' => $inv_id, 'group' => array_filter($item, function ($itm) use ($inv_id) { return $itm['invoice_id'] == $inv_id; }) ); }, array_unique(array_column($item, 'invoice_id')) ); print_r($items); $items = array_values(array_map(function ($inv_id) use ($item) { return array('invoice_id' => $inv_id, 'group' => array_values(array_filter($item, function ($itm) use ($inv_id) { return $itm['invoice_id'] == $inv_id; })) ); }, array_unique(array_column($item, 'invoice_id')) )); print_r($items);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bpEub
function name:  (null)
number of ops:  39
compiled vars:  !0 = $item, !1 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          3        BIND_LEXICAL                                             ~3, !0
   43     4        SEND_VAL                                                 ~3
          5        INIT_FCALL                                               'array_unique'
          6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'invoice_id'
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                         $5      
         12        SEND_VAR                                                 $5
   36    13        DO_ICALL                                         $6      
         14        ASSIGN                                                   !1, $6
   45    15        INIT_FCALL                                               'print_r'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
   47    18        INIT_FCALL                                               'array_values'
         19        INIT_FCALL                                               'array_map'
         20        DECLARE_LAMBDA_FUNCTION                          ~9      [1]
         21        BIND_LEXICAL                                             ~9, !0
   54    22        SEND_VAL                                                 ~9
         23        INIT_FCALL                                               'array_unique'
         24        INIT_FCALL                                               'array_column'
         25        SEND_VAR                                                 !0
         26        SEND_VAL                                                 'invoice_id'
         27        DO_ICALL                                         $10     
         28        SEND_VAR                                                 $10
         29        DO_ICALL                                         $11     
         30        SEND_VAR                                                 $11
   47    31        DO_ICALL                                         $12     
   54    32        SEND_VAR                                                 $12
   47    33        DO_ICALL                                         $13     
         34        ASSIGN                                                   !1, $13
   56    35        INIT_FCALL                                               'print_r'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                                 
         38      > 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/bpEub
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $inv_id, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   37     2        INIT_ARRAY                                       ~2      !0, 'invoice_id'
   38     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !1
   39     5        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          6        BIND_LEXICAL                                             ~3, !0
   41     7        SEND_VAL                                                 ~3
   38     8        DO_ICALL                                         $4      
   41     9        ADD_ARRAY_ELEMENT                                ~2      $4, 'group'
         10      > RETURN                                                   ~2
   43    11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bpEub
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $itm, !1 = $inv_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   40     2        FETCH_DIM_R                                      ~2      !0, 'invoice_id'
          3        IS_EQUAL                                         ~3      !1, ~2
          4      > RETURN                                                   ~3
   41     5*     > RETURN                                                   null

End of Dynamic Function 0

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/bpEub
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $inv_id, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   48     2        INIT_ARRAY                                       ~2      !0, 'invoice_id'
   49     3        INIT_FCALL                                               'array_values'
          4        INIT_FCALL                                               'array_filter'
          5        SEND_VAR                                                 !1
   50     6        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          7        BIND_LEXICAL                                             ~3, !0
   52     8        SEND_VAL                                                 ~3
   49     9        DO_ICALL                                         $4      
   52    10        SEND_VAR                                                 $4
   49    11        DO_ICALL                                         $5      
   52    12        ADD_ARRAY_ELEMENT                                ~2      $5, 'group'
         13      > RETURN                                                   ~2
   54    14*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bpEub
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $itm, !1 = $inv_id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   51     2        FETCH_DIM_R                                      ~2      !0, 'invoice_id'
          3        IS_EQUAL                                         ~3      !1, ~2
          4      > RETURN                                                   ~3
   52     5*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.19 ms | 1014 KiB | 19 Q