Jump to content

Array help


kaveman50

Recommended Posts

Can anyone help me with a multidimensional array? I've never done one before so I'm not sure what to do.

 

A university offers 10 courses at each of three campuses.  The number of students enrolled in each is presented in the table below.

  Find the total number of course enrollments on each campus.

Find the total number of students taking each course.

 

 

                              Item

                    1    2      3

-------------------------------

Store 1        54  23    56

-------------------------------

Store 2        43    54    23

Beginning Inventory

 

Link to comment
Share on other sites

well each row is its own array. each cell is the course number. so the first store would look like

 

$store1['Course1'] = 54;
$store1['Course2'] = 23;
$store1['Course3'] = 56;

 

each of the stores (which are arrays) are stored in another array, so the array that holds everything is basically an array of arrays

$Stores = array($store1, $store2);

 

To access the first store, you would access the first element of the array, like so

$Stores[0];//this is store one

 

well, because its an array, you can treat it like one, if you wanted to, say, access the numer of students in the first course, you would do the following

$Stores[0][0];//54

 

Check out this tutorial for more information: HERE

 

 

Link to comment
Share on other sites

I typed in the wrong chart on my first post.

 

heres the real one.

                        Courses

    1  2  3  4  5  6  7  8  9 10

1  5  15 22 21 12 25 16 11 17 23

2  11 23 51 25 32 35 32 52 25 21

3  2  12 32 32 25 26 29 12 15 11

 

 

Heres my code

<?
$Campus1['Course1'] = 5;
$Campus1['Course2'] = 15;
$Campus1['Course3'] = 22;
$Campus1['Course4'] = 21;
$Campus1['Course5'] = 12;
$Campus1['Course6'] = 25;
$Campus1['Course7'] = 16;
$Campus1['Course8'] = 11;
$Campus1['Course9'] = 17;
$Campus1['Course10'] = 23;

$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];//this is store one



$Campus2['Course1'] = 11;
$Campus2['Course2'] = 23;
$Campus2['Course3'] = 51;
$Campus2['Course4'] = 25;
$Campus2['Course5'] = 32;
$Campus2['Course6'] = 35;
$Campus2['Course7'] = 32;
$Campus2['Course8'] = 52;
$Campus2['Course9'] = 25;
$Campus2['Course10'] = 21;


$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];//this is store two




$Campus3['Course1'] = 2;
$Campus3['Course2'] = 12;
$Campus3['Course3'] = 32;
$Campus3['Course4'] = 32;
$Campus3['Course5'] = 25;
$Campus3['Course6'] = 26;
$Campus3['Course7'] = 29;
$Campus3['Course8'] = 12;
$Campus3['Course9'] = 15;
$Campus3['Course10'] = 11;


$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];//this is store two







echo ($Campus[0]['Course1']);




$sum=0;
while ($campus1+$campus2+$campus3)
{










?>

Link to comment
Share on other sites

<?
$Campus1['Course1'] = 5;
$Campus1['Course2'] = 15;
$Campus1['Course3'] = 22;
$Campus1['Course4'] = 21;
$Campus1['Course5'] = 12;
$Campus1['Course6'] = 25;
$Campus1['Course7'] = 16;
$Campus1['Course8'] = 11;
$Campus1['Course9'] = 17;
$Campus1['Course10'] = 23;

$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];//this is campus one. 

//to access the first course, you do
$Campus[0]['Course1'] = 11;

//remember, since $Campus[0] is $Campus1, you can treat $Campus1['Course1'] and $Campus[0] the same

Link to comment
Share on other sites

It's only outputting 5 for some reason. This is my new code.

<?
$Campus1['Course1'] = 5;
$Campus1['Course2'] = 15;
$Campus1['Course3'] = 22;
$Campus1['Course4'] = 21;
$Campus1['Course5'] = 12;
$Campus1['Course6'] = 25;
$Campus1['Course7'] = 16;
$Campus1['Course8'] = 11;
$Campus1['Course9'] = 17;
$Campus1['Course10'] = 23;

$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0]; 


$Campus[0]['Course1'] = 11;






$Campus2['Course1'] = 11;
$Campus2['Course2'] = 23;
$Campus2['Course3'] = 51;
$Campus2['Course4'] = 25;
$Campus2['Course5'] = 32;
$Campus2['Course6'] = 35;
$Campus2['Course7'] = 32;
$Campus2['Course8'] = 52;
$Campus2['Course9'] = 25;
$Campus2['Course10'] = 21;


$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];



$Campus[0]['Course1'] = 2;






$Campus3['Course1'] = 2;
$Campus3['Course2'] = 12;
$Campus3['Course3'] = 32;
$Campus3['Course4'] = 32;
$Campus3['Course5'] = 25;
$Campus3['Course6'] = 26;
$Campus3['Course7'] = 29;
$Campus3['Course8'] = 12;
$Campus3['Course9'] = 15;
$Campus3['Course10'] = 11;


$Campus = array($Campus1, $Campus2, $Campus3);
$Campus[0];







echo ($Campus[0]['Course1']);
















?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.