我正在尝试复制数组的索引(正在被随机挑选和拼接),以便我知道拼接的顺序。这就是我到目前为止所做的。
Written.php
<!DOCTYPE html>
<html>
<head>
<title>PHP Written Test</title>
</head>
<body onload="$workDamnYou()">
<?php include 'variables.php';
/*
$correctAnswers = array(
);
*/
function setOrder(&$array, &$index,&$i)
{
$array[$i] = $index;
return $array;
}
$x = 1;
$y = 0;
ob_start();
echo "<div style=\"margin-left:25%; \">"
."<form name=\"post\" action=\"score.php\" method=\"POST\">";
while ($x <= 20)
{
$num=array_rand($numbers);
$correctAnswers[$y] = $questions[$numbers[$num]][5];
$idk = $numbers[$num];
$pleaseWork = $correctAnswers[$y];
setOrder($correctAnswers,$idk,$y);
echo "<label>" . $x . ".) " . $questions[$idk][0] . "</label>"
. "<p style=\"text-align:left;\">"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"" . $questions[$idk][1] . " \" required >" . $questions[$numbers[$num]][1] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"" . $questions[$idk][2] . " \">" . $questions[$numbers[$num]][2] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"" . $questions[$idk][3] . " \">" . $questions[$numbers[$num]][3] . "<br>"
. "<input type=\"radio\" name=\"question" . $x . "\" value=\"" . $questions[$idk][4] . " \">" . $questions[$numbers[$num]][4] . "<br>"
. "<label>" . "correct answer is:" . $pleaseWork . $idk . $idk . "</label>"
. "</p>";
//$numberOrder[$x] = $num;
array_splice($numbers,$num,1);
$x++;
$y++;
//setOrder($pleaseWork,$idk);
//echo "does this work: " . $numbers[$num];
}
//}
//bob($correctAnswer);
/*
if (isset($_POST['submit']))
{
ob_end_clean();
$x = 1;
$y = 0;
while ($x <= 20)
{
$uAnswer = $_POST["question" . $x];
if ($uAnswer == $pleaseWork[0])
{
echo "The answer was correct " . "<br><br>";
}
//else
//{
//echo "The correct answer is " . $pleaseWork[$y] . "<br><br>";
//}
$uAnswer = $_POST["question" . $x];
echo "this is the uanswer:" . $uAnswer . "<br>";
echo "This is pleasework:" . $correctAnswers[$y] . "<br>";//this is causing an error cause its null cause i need to pass by reference
$x++;
$y++;
}
}
*/
?>
<br><input style="margin-left:25%;" type="submit" name="submit" value="Finish Test">
</form>
</div>
</body>
</html>
score.php
<!DOCTYPE html>
<html>
<head>
<title>PHP Written Test</title>
</head>
<body>
<?php include 'variables.php';
ob_end_clean();
$x = 1;
$y = 0;
while ($x <= 20)
{
$uAnswer = $_POST["question" . $x];
/*
if ($uAnswer == $pleaseWork[0])
{
echo "The answer was correct " . "<br><br>";
}
//else
//{
//echo "The correct answer is " . $pleaseWork[$y] . "<br><br>";
//}
*/
$uAnswer = $_POST["question" . $x];
echo "this is the uanswer:" . $uAnswer . "<br>";
echo "Trying my function:" . $correctAnswers[0] . "<br>";//this is causing an error cause its null cause i need to pass by reference
$x++;
$y++;
}
?>
</body>
</html>
我决定将数组存储在一个单独的php文件中
<?php
$questions=array(
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is malware?",
"A program a user can use to create and manage spreadsheets",
"The software that controls everything inside the computer. It controls the hardware and software the user works with",
"Programs that intend to damage a users data and system files or allow an outside attacker to gain access to the computer and steal data",
"A web browser",
"Programs that intend to damage a users data and system files or allow an outside attacker to gain access to the computer and steal data"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What program controls items such as the start menu, windows, and the taskbar?",
"Spybot Search and Destroy",
"Internet Explorer",
"Word",
"Explorer",
"Explorer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a folder?",
"A location that stores saved files and programs",
"A paper document inside a file cabinet",
"The Start button",
"A type of file",
"A location that stores saved files and programs"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is an input device?",
"Keyboard",
"Monitor",
"Printer",
"Motherboard",
"Keyboard"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the brain of the computer?",
"GPU",
"CPU",
"Motherboard",
"Monitor",
"CPU"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is an operating system?",
"A word processing program that allows the user to edit text and format it",
"Motherboard",
"An important part of systems files. It manages the interaction between the user, application programs, and hardware",
"A program that infects a computer, copies itself many times using up system resources, and spreads the infection to other computers",
"An important part of systems files. It manages the interaction between the user, application programs, and hardware"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What are the small pictures on the desktop called?",
"Icons",
"Folders",
"Recycle Bin",
"File Type",
"Icons"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the bar at the bottom of the screen called?",
"Shortcut",
"System Tray",
"Program",
"Taskbar",
"Taskbar"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where can you find a list of all the storage devices connected to the computer?",
"Control Panel",
"Computer",
"Documents",
"Desktop",
"Computer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is Task Manager?",
"A program that manages your tasks",
"A program that lets your organize data into databases",
"An operating system",
"A utility program used for managing processes and programs running on the computer",
"A utility program used for managing processes and programs running on the computer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is the default web browser for Windows?",
"Firefox",
"Safari",
"Google Chrome",
"Internet Explorer",
"Internet Explorer"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where do you type links to take you to different web sites?",
"Menu Bar",
"Address Bar",
"Search Bar",
"Favorites Bar",
"Address Bar"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a search engine?",
"Software enabling the user to organize emails",
"A program that allows a user to store, manage, manipulate, and secure data then make queries",
"A tool used to lookup information on the internet",
"The program that runs the internet browser",
"A tool used to lookup information on the internet"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"The first page displayed after starting the web browser is called what?",
"The home page",
"The search engine",
"Web Page 1",
"google.com",
"The home page"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"To refresh a web page you may?",
"Press the F13 key",
"Press the white '-' at the top of the window",
"Press the red 'X' key at the top of the page",
"Click the refresh button",
"Click the refresh button"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Email is?",
"Software programs that can compose, send, and receive email messages",
"The default folder that stores deleted messages",
"A service that allows users to send messages and/or documents to each other over an internet network",
"hotmail.com",
"A service that allows users to send messages and/or documents to each other over an internet network"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Phishing is?",
"Impersonating someone with a similar email address and trying to obtain sensitive information from the recipient",
"Creating a carbon copy of your email",
"Updating software",
"Composing a new email message and sending it",
"Impersonating someone with a similar email address and trying to obtain sensitive information from the recipient"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"The three parts of an email address in order are?",
"User ID, @ symbol, host name",
"GB, MB, KB",
"IP, DNS, ISP",
"CPU, Motherboard, Video Cards",
"User ID, @ symbol, host name"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"What is a carbon copy?",
"A copy of the email sent to the recipient emailed to you",
"A physical copy of the email",
"Writing the email down on paper with pencil",
"Copying the email onto the desktop to view later",
"A copy of the email sent to the recipient emailed to you"
),
array( // [0] is the question, [1]-[4] are the answer choices, [5] is the correct chioce
"Where do you type the recipient's name in a new email?",
"The message itself",
"The 'From' line",
"The Search Bar",
"The 'To' line",
"The 'To' line"
),
);
$numbers = array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19
);
$correctAnswers = array(
);
?>