3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PUSH", "chs_name" => "WF" ], 1 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PUSH", "chs_name" => "WFR" ], 2 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PUSH", "chs_name" => "STK Food" ], 3 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PULL", "chs_name" => "4 Stars" ], 4 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PULL", "chs_name" => "5 Stars" ], 5 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PULL", "chs_name" => "Modern Thai" ], 6 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PULL", "chs_name" => "BBQ Buffet" ], 7 => [ "product_code" => "67021687", "product_name" => "Spaces", "cha_sty_id" => "PULL", "chs_name" => "Chinese" ] ]; $res = []; array_walk($array, function($v, $k) use (&$res){ if(in_array($v['product_code'], array_column($res, 'product_code'))){ array_push($res[$v['product_code']]["push"], $v['chs_name']); array_push($res[$v['product_code']]["pull"], $v['chs_name']); }else{ $res[$v['product_code']] = [ "product_code" => $v['product_code'], "product_name" => $v['product_name'], "push" => [$v['chs_name']], "pull" => [$v['chs_name']] ]; } }); echo '<pre>'; print_r(array_values($res));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jduqg
function name:  (null)
number of ops:  16
compiled vars:  !0 = $array, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   53     1        ASSIGN                                                   !1, <array>
   54     2        INIT_FCALL                                               'array_walk'
          3        SEND_REF                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          5        BIND_LEXICAL                                             ~4, !1
   66     6        SEND_VAL                                                 ~4
   54     7        DO_ICALL                                                 
   68     8        ECHO                                                     '%3Cpre%3E'
   69     9        INIT_FCALL                                               'print_r'
         10        INIT_FCALL                                               'array_values'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
         15      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 30
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jduqg
function name:  {closure}
number of ops:  44
compiled vars:  !0 = $v, !1 = $k, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   55     3        INIT_FCALL                                               'in_array'
          4        FETCH_DIM_R                                      ~3      !0, 'product_code'
          5        SEND_VAL                                                 ~3
          6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !2
          8        SEND_VAL                                                 'product_code'
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                         $5      
         12      > JMPZ                                                     $5, ->30
   56    13    >   INIT_FCALL                                               'array_push'
         14        FETCH_DIM_R                                      ~6      !0, 'product_code'
         15        FETCH_DIM_W                                      $7      !2, ~6
         16        FETCH_DIM_W                                      $8      $7, 'push'
         17        SEND_REF                                                 $8
         18        FETCH_DIM_R                                      ~9      !0, 'chs_name'
         19        SEND_VAL                                                 ~9
         20        DO_ICALL                                                 
   57    21        INIT_FCALL                                               'array_push'
         22        FETCH_DIM_R                                      ~11     !0, 'product_code'
         23        FETCH_DIM_W                                      $12     !2, ~11
         24        FETCH_DIM_W                                      $13     $12, 'pull'
         25        SEND_REF                                                 $13
         26        FETCH_DIM_R                                      ~14     !0, 'chs_name'
         27        SEND_VAL                                                 ~14
         28        DO_ICALL                                                 
   55    29      > JMP                                                      ->43
   59    30    >   FETCH_DIM_R                                      ~16     !0, 'product_code'
   60    31        FETCH_DIM_R                                      ~18     !0, 'product_code'
         32        INIT_ARRAY                                       ~19     ~18, 'product_code'
   61    33        FETCH_DIM_R                                      ~20     !0, 'product_name'
         34        ADD_ARRAY_ELEMENT                                ~19     ~20, 'product_name'
   62    35        FETCH_DIM_R                                      ~21     !0, 'chs_name'
         36        INIT_ARRAY                                       ~22     ~21
         37        ADD_ARRAY_ELEMENT                                ~19     ~22, 'push'
   63    38        FETCH_DIM_R                                      ~23     !0, 'chs_name'
         39        INIT_ARRAY                                       ~24     ~23
         40        ADD_ARRAY_ELEMENT                                ~19     ~24, 'pull'
   59    41        ASSIGN_DIM                                               !2, ~16
   63    42        OP_DATA                                                  ~19
   66    43    > > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.96 ms | 1008 KiB | 19 Q