3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param array $array * @param string $column * * @return array */ function mergeOnEquals(array $array, $column) { $result = []; foreach ($array as $subArray) { $index = $subArray[$column]; if (isset($result[$index])) { foreach($subArray as $key => $value) { if (!isset($result[$index][$key])) { $result[$index][$key] = $value; } elseif ($result[$index][$key] != $value) { $result[$index][$key] .= ",$value"; } } } else { $result[$index] = $subArray; } } return array_values($result); } $array = [ [ 'carriertype' => null, 'radiotype' => 'RRUS 12 B2', 'serialnumber' => 'CF82943634', 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 16, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => 'RRU-7', 'userlabletext' => '225011_1_4', 'flag' => 'Yes', ], [ 'carriertype' => null, 'radiotype' => 'RRUS 12 B2', 'serialnumber' => 'CF82961338', 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 15, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => 'RRU-8', 'userlabletext' => '225011_2_4', 'flag' => 'Yes', ], [ 'carriertype' => null, 'radiotype' => 'RRUS 12 B2', 'serialnumber' => 'CF82943628', 'market' => 'Detroit Westland - DET 5', 'bts' => '225011', 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 14, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => 'RRU-9', 'userlabletext' => '225011_3_4', 'flag' => 'Yes', ], [ 'radiotype' => null, 'carriertype' => null, 'serialnumber' => null, 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 1, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => null, 'userlabletext' => '___B', 'flag' => 'Yes', ], [ 'radiotype' => null, 'carriertype' => null, 'serialnumber' => null, 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 1, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => null, 'userlabletext' => '___E', 'flag' => 'Yes', ], [ 'carriertype' => 'AWS', 'radiotype' => 'RRUS 12 B4', 'serialnumber' => 'CF81666912', 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 16, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => 'RRU-5', 'userlabletext' => '225011_2_2', 'flag' => 'Yes', ], [ 'carriertype' => 'AWS', 'radiotype' => 'RRUS 12 B4', 'serialnumber' => 'CF81666918', 'market' => 'Detroit Westland - DET 5', 'bts' => 225011, 'Host' => '225011_21_MILE_and_ROMEO_PLANK', 'resourceId' => 0, 'type' => 'XMU', 'port' => 14, 'EP_AuxPlugInUnit_AuxPlugInUnitId' => 'RRU-6', 'userlabletext' => '225011_3_2', 'flag' => 'Yes', ], ]; print_r(mergeOnEquals($array, 'port'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gCXIu
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
  132     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'mergeonequals'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'port'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function mergeonequals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 35
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 32
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 29
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 30
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/gCXIu
function name:  mergeOnEquals
number of ops:  41
compiled vars:  !0 = $array, !1 = $column, !2 = $result, !3 = $subArray, !4 = $index, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        ASSIGN                                                   !2, <array>
   13     3      > FE_RESET_R                                       $8      !0, ->35
          4    > > FE_FETCH_R                                               $8, !3, ->35
   14     5    >   FETCH_DIM_R                                      ~9      !3, !1
          6        ASSIGN                                                   !4, ~9
   15     7        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !4
          8      > JMPZ                                                     ~11, ->32
   16     9    > > FE_RESET_R                                       $12     !3, ->30
         10    > > FE_FETCH_R                                       ~13     $12, !5, ->30
         11    >   ASSIGN                                                   !6, ~13
   17    12        FETCH_DIM_IS                                     ~15     !2, !4
         13        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     ~15, !6
         14        BOOL_NOT                                         ~17     ~16
         15      > JMPZ                                                     ~17, ->20
   18    16    >   FETCH_DIM_W                                      $18     !2, !4
         17        ASSIGN_DIM                                               $18, !6
         18        OP_DATA                                                  !5
         19      > JMP                                                      ->29
   19    20    >   FETCH_DIM_R                                      ~20     !2, !4
         21        FETCH_DIM_R                                      ~21     ~20, !6
         22        IS_NOT_EQUAL                                             !5, ~21
         23      > JMPZ                                                     ~22, ->29
   20    24    >   NOP                                                      
         25        FAST_CONCAT                                      ~25     '%2C', !5
         26        FETCH_DIM_RW                                     $23     !2, !4
         27        ASSIGN_DIM_OP                .=               8          $23, !6
         28        OP_DATA                                                  ~25
   16    29    > > JMP                                                      ->10
         30    >   FE_FREE                                                  $12
         31      > JMP                                                      ->34
   24    32    >   ASSIGN_DIM                                               !2, !4
         33        OP_DATA                                                  !3
   13    34    > > JMP                                                      ->4
         35    >   FE_FREE                                                  $8
   28    36        INIT_FCALL                                               'array_values'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $27     
         39      > RETURN                                                   $27
   29    40*     > RETURN                                                   null

End of function mergeonequals

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.78 ms | 1403 KiB | 18 Q