Confusing foreach loop - accessing and then re-storing values into variables from array
===

I have the following multidimensional array:   
 

    Array
        (
            [0] => Array
                (
                    [name] => team0
                    [games] => Array
                        (
                            [0] => 3
                            [1] => 2
                            [2] => 1
                        )
        
                )
        
            [1] => Array
                (
                    [name] => team1
                    [games] => Array
                        (
                            [0] => 2
                            [1] => 3
                            [2] => 0
                        )
        
                )
        
            [2] => Array
                (
                    [name] => team2
                    [games] => Array
                        (
                            [0] => 1
                            [1] => 0
                            [2] => 3
                        )
        
                )
        
            [3] => Array
                (
                    [name] => team3
                    [games] => Array
                        (
                            [0] => 0
                            [1] => 1
                            [2] => 2
                        )
        
                )
        
        )

I am trying to traverse through the array and store information from the array in individual variables to execute a queries on a database using these variables as parameters. I am finding working with this multidimensional array very confusing and I am struggling to understand how to properly iterate over the array. As it is, this is my code... which at this stage is more just me meddling with foreach loops, trying to grasp a better understanding of how I can achieve what I need to do. There is a problem with this code as it is, after every team name "Array" is also echoed out.

		

	foreach ($arrTeam as $array) 
				foreach ($array as $groupid => $group){
					$in_groupID = $groupid+1;
					foreach ($group as $name) {
						if (isset($name)) echo $name.'<br>'; 
					}					
				}

Basically what I want to do is fetch a groupid and teamname from the array, store them in `$in_groupID` and `$in_teamName`, and then traverse deeper into the array and grab each game for that specific team one game at a time - executing the query on the database for each game I grab. The query itself is not a problem, it's iterating through this confusing loop in the way that I want to and storing the values as parameters for the execution.

Any help would be majorly appreciated. As I said, I'm not concerned with executing the database query and whatnot, I can easily fix that and add it in later, I just need to get my head around storing the parameters from the loop for the execute.

Thanks a lot for any help.