kaveman50 Posted November 2, 2009 Share Posted November 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/ Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 . Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949130 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949135 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 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) { ?> Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949495 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 <? $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 Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949512 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 I'm still confused about how you combined all 3. Do you have to do a loop? Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949616 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 this is how you combine all three $Campus = array($Campus1, $Campus2, $Campus3); did you check out the tutorial? Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949625 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 Oh I didn't see the link. I'll go check it out. Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949627 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 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']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949633 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 I'm having a hard time relating the tutorial with the program itself. Does anyone know what's wrong? Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949656 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 or not necessarily what's wrong, but what to add Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949660 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 . Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949677 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 . Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949687 Share on other sites More sharing options...
kaveman50 Posted November 2, 2009 Author Share Posted November 2, 2009 Mikesta or anyone else know what to do? Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949698 Share on other sites More sharing options...
mikesta707 Posted November 2, 2009 Share Posted November 2, 2009 what is it supposed to say? Quote Link to comment https://forums.phpfreaks.com/topic/179918-array-help/#findComment-949772 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.