How to use two diamensional arrays in 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
greeshma
Forum Newbie
Posts: 3
Joined: Thu Jun 22, 2006 7:25 am

How to use two diamensional arrays in PHP?

Post by greeshma »

I have a list of courses like PHP,C++..etc. and each courses consists a number of modules.For example the PHP course contains modules are 1.introduction
2.basics
3.syntax etc..
I want to display each course and its correspoding modules using a for loop.

I have all this details in an array from the database and i want to store it some other arrayand display the details in a table.How can i do it?
User avatar
bmcewan
Forum Commoner
Posts: 55
Joined: Wed Jun 02, 2004 7:19 am
Location: West Yorkshire, UK.

Post by bmcewan »

Can you show us what your expected table layout should be and also the structure of the data returned from your db query.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Show us your current array structure.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You can use array() to assign multi-dimensional arrays. Here is an associative array's example:

Code: Select all

$var = array(
        'key1' => "this is a string value",
        'key2' => $the_value_in_this_var_will_be_used,
        'key3' => array(
            'key3-key1' => "this is a string value",
            'key3-key2' => array(
                'key3-key2-key1' => "this is a string value",
                'key3-key2-key2' => "this is another string value",
                 ),
             ),
    );
Ulitmately you need to play with it a little and try different combinations.
(#10850)
Post Reply