This is my array. And i need to concat array values if duplicate exists.
Array
(
[0] => Array
(
[id] => 3
[location_id] => 2
[location_name] => 1st Floor
[type] => 1
)
[1] => Array
(
[id] => 6
[location_id] => 2
[location_name] => 1st Floor
[type] => 1
)
[2] => Array
(
[id] => 7
[location_id] => 1
[location_name] => Ground Floor
[type] => 1
)
)
And below is my code, which doesn't concat on unique values.
$conct= array();
foreach ($myArray as $array)
{
foreach ($array as $key => $value)
{
if ( ! isset($merged[$key]))
{
$conct[$key] = $value;
}
else
{
$conct[$key] .= ",".$value;
}
}
}
This is giving me.
Array
(
[0] => Array
(
[id] => 3,6,7
[location_id] => 2,2,1
[location_name] => 1st Floor,1st Floor,Ground Floor
[type] => 1,1,1
)
)
And i need to concat the values based on unique location_id and location_name.
My result array should be.
Array
(
[0] => Array
(
[id] => 3,6
[location_id] => 2,2
[location_name] => 1st Floor,1st Floor
[type] => 1,1
)
[1] => Array
(
[id] => 7
[location_id] => 1
[location_name] => Ground Floor
[type] => 1
)
)
How to achieve this?