I need to figure out a logic that has me confused. I have an array that looks like this.
array (
0 => array (
'invoice_id' => 'WUI_588'
'email' => '[email protected]'
),
1 => array (
'invoice_id' => 'WUI_588'
'email' => '[email protected]'
),
2 => array (
'invoice_id' => 'WUI_589'
'email' => '[email protected]'
),
3 => array (
'invoice_id' => 'WUI_589'
'email' => '[email protected]'
),
4 => array (
'invoice_id' => 'WUI_590'
'email' => '[email protected]'
),
5 => array (
'invoice_id' => 'WUI_590'
'email' => '[email protected]'
),
6 => array (
'invoice_id' => 'WUI_591'
'email' => '[email protected]'
),
7 => array (
'invoice_id' => 'WUI_591'
'email' => '[email protected]'
),
)
So if I were to print the array in table layout I would get something like this:-
INDEX | INVOICE ID | EMAIL
0 | WUI_588 | [email protected]
1 | WUI_588 | [email protected]
2 | WUI_589 | [email protected]
3 | WUI_589 | [email protected]
What I want is something like this:-
INDEX | INVOICE ID | EMAIL
0 | WUI_588 | [email protected], [email protected]
1 | WUI_589 | [email protected], [email protected]
....and so on. One of the attempts I made is this,
foreach ($array as $key => $value) {
$invoiceidbucket[] = $value['invoice_id'];
if(in_array($value['invoice_id'], $invoiceidbucket)) {
$value['merged_email'][] = $value['email'];
//Clearing array
$invoiceidbucket = array;
}
}