<?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'));
- Output for 5.6.0 - 5.6.27, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- Array
(
[0] => Array
(
[carriertype] => AWS
[radiotype] => RRUS 12 B2,RRUS 12 B4
[serialnumber] => CF82943634,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-7,RRU-5
[userlabletext] => 225011_1_4,225011_2_2
[flag] => Yes
)
[1] => Array
(
[carriertype] =>
[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
)
[2] => Array
(
[carriertype] => AWS
[radiotype] => RRUS 12 B2,RRUS 12 B4
[serialnumber] => CF82943628,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-9,RRU-6
[userlabletext] => 225011_3_4,225011_3_2
[flag] => Yes
)
[3] => Array
(
[radiotype] =>
[carriertype] =>
[serialnumber] =>
[market] => Detroit Westland - DET 5
[bts] => 225011
[Host] => 225011_21_MILE_and_ROMEO_PLANK
[resourceId] => 0
[type] => XMU
[port] => 1
[EP_AuxPlugInUnit_AuxPlugInUnitId] =>
[userlabletext] => ___B,___E
[flag] => Yes
)
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Array
(
[0] => Array
(
[carriertype] => AWS
[radiotype] => RRUS 12 B2,RRUS 12 B4
[serialnumber] => CF82943634,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-7,RRU-5
[userlabletext] => 225011_1_4,225011_2_2
[flag] => Yes
)
[1] => Array
(
[carriertype] =>
[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
)
[2] => Array
(
[carriertype] => AWS
[radiotype] => RRUS 12 B2,RRUS 12 B4
[serialnumber] => CF82943628,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-9,RRU-6
[userlabletext] => 225011_3_4,225011_3_2
[flag] => Yes
)
[3] => Array
(
[radiotype] =>
[carriertype] =>
[serialnumber] =>
[market] => Detroit Westland - DET 5
[bts] => 225011
[Host] => 225011_21_MILE_and_ROMEO_PLANK
[resourceId] => 0
[type] => XMU
[port] => 1
[EP_AuxPlugInUnit_AuxPlugInUnitId] =>
[userlabletext] => ___B,___E
[flag] => Yes
)
)
preferences:
187.17 ms | 409 KiB | 203 Q