I have no idea where to start on this! I have an array containing questions and an array containing the four multiple choices for those questions. So I need $all_questions[0] = array ($all_choices[0], $all_choices[1], $all_choices[2], $all_choices[3]). I need it to go through the whole array and set 4 choices to each question. Can someone give me atleast a little tip on this. Right now I just have it printing a random question.
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Midterm</title>
</head>
<body>
<?php
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~ E_NOTICE);
//read questions file
function read_file ( $file ){
//get handle to file
$handle = fopen ( $file , "r" );
//if $handle is false, the file wasn't found
if ( $handle == false ){
die ( "File not found!" );//notify programmer of error
}
//get size of file
$size = filesize ( $file );
// if size is zero, the file contains nothing
if ($size == 0 ){
die ( "This file contains nothing!" );//notify programmer of error
}
//read contents of file using fread
$contents = fread ( $handle, $size );
//if $contents is NULL, the file is empty
if ( $contents == NULL ){
die ( "This file is empty!" );
}
//close handle to file
fclose ($handle);
//return file contents
return $contents;
}
//read file questions.txt
$all_questions = read_file ( "questions.txt" );
//use explode to put list of questions separated by a ~ into an array
$all_questions = explode ( "~" , $all_questions );
//read file choices.txt
$all_choices = read_file ( "choices.txt" );
//use explode to put list of choices separated by a ~ into an array
$all_choices = explode ( "~" , $all_choices );
//get 4 random question and choices and print
$limit = rand(0, (count($all_questions)-1));
echo $all_questions[$limit];
?>
</body>
</html>
This post has been edited by dls76: 14 Mar, 2008 - 05:00 PM