I have following array inside foreach loop and I want to merge array value(append with comma) where "key value" (column_name,match,coll) is same/duplicate. In short I want to combine duplicate array values. How can I do this? Here is my current array
Array
(
[id] => 86
[column_name] => Accommodation
[text] => hotel
[match] => 2
[coll] => 1
)
Array
(
[id] => 87
[column_name] => Accommodation
[text] => staff
[match] => 2
[coll] => 1
)
Array
(
[id] => 91
[column_name] => Accommodation
[text] => marriot
[match] => 3
[coll] => 1
)
My expected result:
Array
(
[id] => 86
[column_name] => Accommodation
[text] => hotel staff
[match] => 2
[coll] => 1
)
Array
(
[id] => 91
[column_name] => Accommodation
[text] => marriot
[match] => 3
[coll] => 1
)
Tried with following code:
foreach ($result as $key =>$element) {
if($element['column_name'] == 'Accommodation'){
echo "<pre>";print_R($element);
}
}