doudou_3636 2014-04-19 03:46
浏览 36
已采纳

复制数组的索引(随机选择然后拼接)到另一个数组中,以便我知道它拼接的顺序是什么

I am trying to copy the index of an array (that is being randomly picked and spliced) so that I know what order it was spliced in. This is what I have so far.

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>

I decide to store the arrays in a seperate php file

 <?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(

 );




 ?> 
  • 写回答

1条回答 默认 最新

  • dongmaijie5200 2014-04-20 00:20
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料