You could do this by looping through the fields 3 times and checking the parent. The value of $field['parent']
will be the group key for the group the field is in. So for example if your group key for the first group is group_5664a3d9a775b
foreach ($fields as $field_name => $field) {
if ($field['parent'] != 'group_5664a3d9a775b') {
// not in first group
continue;
}
// display field
}
// to 2 more times for each of the other groups