Current location: Hot Scripts Forums » General Community » Script Requests » [PHP] Array question


[PHP] Array question

Reply
  #1 (permalink)  
Old 04-05-04, 10:44 AM
UmiSal UmiSal is offline
Newbie Coder
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy [PHP] Array question

I have a 2D array called $questions[$i][$j]. The first...brackets are associated with the index $i that can be 0 to 9. The $j has values from 0 to 4. What this array simply contains is the data of 10 questions. If we have the following question, which is the 1st in a list of 10 questions (the () corresponds a radio button):

Question 1: What is the thing?
() Choice1
() Choice2 (this is the correct choice)
() Choice3

its will be stored like:
$questions[0][0] = "What is the thing?";
$questions[0][1] = "Choice1";
$questions[0][2] = "Choice1";
$questions[0][3] = "Choice1";
$questions[0][4] = 2;

where the two is the value corresponding to the right choice of the question.

Now, when the user answers all 10 questions, his answers will be stored in another 1 dimentional array called $answers[], that has 10 elements that are an ordered list of the choices he made for each 10 questions (i.e. 1 or 2 or 3 for each question according to the choice the user chose: 1st, 2nd or 3rd choice).

After that i want to see if he's answered which question right so that i could increment the variable $score for each right answer.

I made the following for loop to check each value of the $answers[] array and the 5th element in every sub-array of the 10 sub-arrays in the array $questions[][] , but it doesn't work.

CODE:

for ($i=0; $i<10; $i++)
{ if($questions[$i][4] == $answers[$i])
$score++;
}



The score stays 0 no matter how the user answers. I checked the $answers array and it seems to be storing the answers alright, but the problem seems to be in the $questions[][] array. When i place a print statement in the for loop to print $questions[$i][4], it prints NOTHING!

please help...
Reply With Quote
  #2 (permalink)  
Old 04-05-04, 01:52 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
are you sure that you included the $questions array in the answers section/page?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I write an array to a file? bark PHP 2 03-30-04 12:28 PM
simple array question jimcart JavaScript 1 03-19-04 05:38 PM
Easy question about arrays... tempa PHP 4 03-09-04 06:13 AM
question and answer software jaydifox C/C++ 0 02-21-04 09:26 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM


All times are GMT -5. The time now is 11:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.