NYCPHP Meetup

NYPHP.org

[nycphp-talk] Multidimensional Arrays?

Jose Villegas jv_nyphp at duikerbok.com
Wed Jul 7 17:03:50 EDT 2004


what about something like this:

$all_teams = array(
	'TEAM 1' => array(
		'Year 1' => 8,
		'Year 2' => 9,
		'Year 3' => 22
	),
	'TEAM 2' => array(
		'Year 1' => 18,
		'Year 2' => 94,
		'Year 3' => 12
	),
	etc...
);

$year1 = 0;
$year2 = 0;
$year3 = 0;

foreach ($all_teams as $next_array)
{
	$year1 += $next_array['Year 1'];
	$year2 += $next_array['Year 2'];
	$year3 += $next_array['Year 3'];
}

-jose

On Jul 7, 2004, at 1:14 PM, harvey wrote:

> Hello,
>
> I have code that loops through the database and outputs something like 
> the
> following:
>
>
> TEAM 1
>
> Year 1    Year 2     Year 3
>
> 8         9          22
>
> TEAM 2
>
> Year 1     Year 2     Year 3
>
> 18         94         12
>
> TEAM 3
>
> Year 1     Year 2     Year 3
>
> 23         44         45
>
> ALL TEAMS
>
> Year 1     Year 2     Year 3
>
> ??         ??         ??
>
>
> I can't figure out how to easily get the ?? totals. I think I want a 
> major
> array of three minor arrays (I probably just invented my own 
> vocabulary):
> the major array would increment by one each year; the three minor 
> arrays
> would hold the Year 1 values, Year 2 values, and Year 3 values.
> Conceptually, it would be something like $all_teams[$year_id][ ]. Is
> something like that possible? I know that php allows multidimensional
> arrays, but I guess I don't know the proper syntax or usage.
>
> Thanks in advance for any help!
>
> Harvey




More information about the talk mailing list