how to declar the 2 dimentional array php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prakumbe
Forum Newbie
Posts: 2
Joined: Fri May 16, 2008 7:26 am

how to declar the 2 dimentional array php

Post by prakumbe »

i am getting the values from the database table as an array like cusomer name, years, complaints.
cusomer names as rows and years as columns. complaints as values. all values are geeting from the db table.
xys cusomer in 2008 has 10 complaints
and abc cusomer in 2009 has 15 complaints and
asdf cusomer in 2010 has 20 complaints
like that i want display. give some. i am not good at arrays. please help to me.
Regards,
qumar.
sylsft
Forum Newbie
Posts: 2
Joined: Mon May 26, 2008 5:36 pm
Location: Waterloo, Ontario, Canada

Re: how to declar the 2 dimentional array php

Post by sylsft »

The easiest way would be to simply initialize arrays within arrays, like:

Code: Select all

$allComplaints = array(
    '2008', array($complaint1, $complaint2, ...),
    '2009', array($complaint1, $complaint2, ...),
    ...
    );
Then you can access them like:

Code: Select all

$aComplaint = $allComplaints['2008'][0];
Post Reply