I currently have an array which looks like:
Array
(
[0] => Array
(
[id] => 1
[name] => Test 1
[age] => 42
[another_id] => 5
)
[1] => Array
(
[id] => 2
[name] => Test 2
[age] => 47
[another_id] => 3
)
[2] => Array
(
[id] => 3
[name] => Test 3
[age] => 30
[another_id] => 2
)
[3] => Array
(
[id] => 4
[name] => Test 7
[age] => 60
[another_id] => 3
)
[4] => Array
(
[id] => 5
[name] => Test 10
[age] => 38
[another_id] => 3
)
)
What I am looking to do is take all of the array items and print out a report of the items but group them by the 'another_id' field. For example the outcome I am looking for is:
REPORT
**Another id (2)**
Name: Test 3
**Another id (3)**
Name: Test 2
Name: Test 7
Name: Test 10
**Another id (5)**
Name: Test 1
I can group the items together but they all remain in a single array and I can't seem to separate them from each other to generate a report
$grouped_types = array();
foreach($invalid_results as $type){
$grouped_types[$type['another_id']][] = $type;
}
print_r($grouped_types);
Can anyone help me? Much appreciated!