I'm having trouble printing the results of this array in loop (to be displayed on the front end). The objective to be able to get the chapter name (eg, Chapter_Name_Unique), that chapter name's total chapter post views count, and then the fullname of each chapter_member within that chapter name (or group). I'm thinking that something isn't structured properly here, because I'm having issues looping through.
Is my logic off?
print_r looks like this:
Array
(
 [Chapter_Name_Unique] => Array
    (
        [chapter_post_views_count] => 3338
        [chapter_members] => Array
            (
                [0] => Array
                    (
                        [post_views_count] => 3338
                        [first_name] => Mary
                        [last_name] => Jane
                        [fullname] => maryjane
                        [chapter_name] => Chapter_Name_Unique
                    )
            )
    )
[Chapter_Name_Unique_2] => Array
    (
        [chapter_post_views_count] => 783
        [chapter_members] => Array
            (
                [0] => Array
                    (                    
                        [post_views_count] => 404
                        [first_name] => Betty
                        [last_name] => Lou
                        [fullname] => bettylou
                        [chapter_name] => Chapter_Name_Unique_2
                    )
                [1] => Array
                    (
                        [post_views_count] => 379
                        [first_name] => Judy
                        [last_name] => Jones
                        [fullname] => judyjones
                        [chapter_name] => Chapter_Name_Unique_2
                    )
            )
    )
)
and the actual functions look like this:
$grouped_types = array();
// to add together post counts of group members
foreach($users as $chapter){ 
$grouped_types[$chapter['chapter_name']]['chapter_post_views_count'] += $chapter['post_views_count'];
}
// to group on top level by chapter_name
foreach($users as $chapter){ 
$grouped_types[$chapter['chapter_name']]['chapter_members'][] = $chapter;
}
echo "<pre>";
print_r( $grouped_types );
echo "</pre>";
 
    