NYCPHP Meetup

NYPHP.org

[nycphp-talk] Multidimensional Arrays?

Daniel Convissor danielc at analysisandsolutions.com
Wed Jul 7 17:39:12 EDT 2004


On Wed, Jul 07, 2004 at 01:14:41PM -0400, harvey wrote:
> 
> 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
...snip...
> ALL TEAMS
> Year 1     Year 2     Year 3
> ??         ??         ??

Pseudo code...  PLEASE extrapolate the concept here to fit your actual 
needs.

while ($row = fetchrow($result)) {
    echo $row['year'] . ' ' . $row['score'];
    $total[$row['year']] += $row['score'];
}

Then, to get the totals:

foreach ($total as $year => $val) {
   echo "$year = $val";
}


> I know that php allows multidimensional
> arrays, but I guess I don't know the proper syntax or usage.

$x['key1']['level2']['level3']['level4']['yougettheidea']

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list