Php quiz with answers

Php Quiz Online with Answer

PHP Online Quiz Following quiz provides Multiple Choice Questions (MCQs) related to PHP programming language. You will have to read all the given answers and click on view answer option.

These php online test quizzes on php web development, database have answers available with pdf, which in very useful in interview and also in php subject exam.

1. PHP Stands for…

A. Php Hypermarkup Preprocessor

B. Php Hypertext Processor

C. Php Hypermarkup Processor

D. Php Hypertext Preprocessor

2. PHP is which type scripting language?

3. Which of the following is used to add comments in PHP?

4. PHP scripts are executed on?

B. It depends on PHP scripts

5. Variables are case-sensitive in PHP?

6. PHP Scripts starts with?

7. Which of the following statements prints in PHP?

8. In PHP Language variables name starts with?

9. In PHP, each statement must be end with?

10. In PHP Language variables are case sensitive?

11. Data for a cookie stored in _____ in PHP?

B. It depends on PHP Coding

12. What does the PHP Interpreter do?

A. It creates connection between ISP & Server

B. It processes the HTML and PHP files

C. It translates User Language to System Language

13. In PHP a variable needs to be declaring before assign…

14. Which of the following is not the scope of Variable in PHP?

15. PHP is which typed language?

16. Which is the Concatenation Operator in PHP?

17. Where session_start() function must appear in PHP?

18. How to define a variable in PHP?

19. What does fopen() function do in PHP?

A. It used to open folders in PHP

B. It used to open files in PHP

C. It used to open Remote Computer

D. It used to open Remote Server

20. What does sprintf() function do in PHP?

A. it sends output to a variable converting into string

B. it prints the output of program

C. it prints the output of program converting into string

D. it sends output to a variable

21. What does isset() function do in PHP?

A. It checks whether variable is free or not

B. There is no such function in PHP

C. It checks whether variable is string or integer

D. It checks whether variable is set or not

Источник

PHP Online Quiz

Following quiz provides Multiple Choice Questions (MCQs) related to PHP. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 — Using which of the following way can you embed PHP code in an HTML page?

Answer : D

Explanation

All of the above options are correct.

Q 2 — Which of the following type of variables are named and indexed collections of other values?

Answer : B

Explanation

Arrays: are named and indexed collections of other values.

Q 3 — Which of the following is correct about constants?

Answer : C

Explanation

Both of the above options are correct.

Q 4 — Which of the following array represents an array with a numeric index?

Answer : A

Explanation

Numeric array − An array with a numeric index. Values are stored and accessed in linear fashion.

Q 5 — Which of the following variable is used to get user’s browser and operating system details in PHP?

Answer : A

Explanation

One of the environemnt variables set by PHP is HTTP_USER_AGENT which identifies the user’s browser and operating system.

Q 6 — Doubly quoted strings are treated almost literally, whereas singly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

Answer : B

Explanation

Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

Q 7 — Which of the following function is used to check if a file exists or not?

Answer : D

Explanation

File’s existence can be confirmed using file_exist() function which takes file name as an argument.

Q 8 — Which of the following provides content type of the uploaded file in PHP?

Answer : D

Explanation

$_FILES[‘file’][‘type’] − it provides the content type of the uploaded file in PHP.

Q 9 — Which of the following is correct about eregi() function?

Answer : B

Explanation

The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.

Q 10 — Can you create a class in PHP?

Answer : A

Explanation

Yes! class can be created in PHP.

Источник

Simple PHP Quiz Without Database (Free Download)

Welcome to a tutorial on how to create a quiz in PHP. Want to add a quiz to your website, but don’t need all the crazy admin features and stuff? Here’s a quick sharing of my simple version, without a database – Read on!

TABLE OF CONTENTS

PHP QUIZ

All right, let us now get into the ways to create a simple quiz in PHP.

STEP 1) QUESTIONS & ANSWERS

 "Which is the biggest island in the world?", "o" => ["Bora Bora", "Greenland", "Bali", "Borneo"], "a" => 1 ], [ "q" => "Which country produces the most coffee?", "o" => ["India", "Vietnam", "Brazil", "Indonesia"], "a" => 2 ], [ "q" => "Which country has the most vending machines?", "o" => ["Japan", "US", "Singapore", "Russia"], "a" => 0 ], [ "q" => "How long does it take for food to pass through the human body?", "o" => ["12 hours", "26 hours", "47 hours", "53 hours"], "a" => 3 ] ];

Since we don’t have a database, the only way is to store the questions and answers in an array. This should be pretty self-explanatory.

  • q The question itself.
  • o The available options. Take note, you can have as many options as you like. It does not have to be exactly 4.
  • a Which option is the correct answer. Take note again, an array starts with index 0. So 0 states that the first option is correct.

STEP 2) QUIZ PAGE

  • quizWrap The quiz wrapper itself.
  • quizQn The current question.
  • quizAns To place all the available options.

STEP 3) AJAX HANDLER

  • We simply send a $_POST[«qn»] to this script to get the selected question/options.
  • Just a small note. On the first question $_POST[«qn»]==0 , we will return the total number of questions count($quiz) .

STEP 4) THE JAVASCRIPT

4A) QUIZ PROPERTIES

// (A) PROPERTIES // (A1) HTML ELEMENTS hQn : null, // question hAns : null, // answer // (A2) QUIZ FLAGS all : 0, // total number of questions now : 0, // current question ans : 0, // current correct answer score : 0, // current score

The Javascript is probably the most confusing part. Not going to explain line-by-line, but all these flags are necessary to drive the quiz.

4B) QUIZ INIT

// (B) INIT QUIZ init : () => < quiz.hQn = document.getElementById("quizQn"); quiz.hAns = document.getElementById("quizAns"); quiz.load(); >window.addEventListener("DOMContentLoaded", quiz.init);

quiz.init() is the first thing that will run on page load. All it does is to get the question and options HTML , then proceed to load the first question.

4C) LOAD THE NEXT QUESTION

// (C) LOAD NEXT QUESTION/ANSWER load : () => < // (C1) FORM DATA let data = new FormData(); data.append("qn", quiz.now); // (C2) AJAX FETCH fetch("3-ajax.php", < method:"POST", body:data >) .then(res => res.json()).then(qna => < // TOTAL NUMBER OF QUESTIONS if (quiz.now == 0) < quiz.all = qna.all; >// SET THE QUESTION quiz.hQn.innerHTML = qna.q; // SET THE OPTIONS quiz.ans = qna.a; quiz.hAns.innerHTML = ""; qna.o.forEach((val, idx) => < let o = document.createElement("div"); o.className = "option"; o.id = "opt"+idx; o.innerHTML = val; o.onclick = () =>quiz.pick(idx); quiz.hAns.appendChild(o); >); >); >

This is quite a bit of code, but keep calm and look carefully.

  • (A2) We use the quiz.now flag to track the current question number.
  • (C1) We need to pass this flag to 3-ajax.php to get the correct question and options.
  • (C2) Send quiz.now to 3-ajax.php . Draw the question and options.

4D) PICK AN OPTION

// (D) PICK AN OPTION pick : idx => < // (D1) DETACH ALL ONCLICK & SET RIGHT/WRONG CSS for (let o of quiz.hAns.getElementsByClassName("option")) < o.onclick = ""; >// (D2) CORRECT ANSWER? let o = document.getElementById("opt"+idx); if (idx == quiz.ans) < quiz.score++; o.classList.add("correct"); >else < o.classList.add("wrong"); >// (D3) NEXT QUESTION OR END GAME quiz.now++; setTimeout(() => < if (quiz.now < quiz.all) < quiz.load(); >else < quiz.hQn.innerHTML = `You have answered $of $ correctly.`; quiz.hAns.innerHTML = ""; > >, 1000); >
  • Update the score quiz.score .
  • Update the current question number quiz.now .
  • Load the next question.

It’s actually simple, but just long-winded.

4E) RESET THE QUIZ

For you guys who need to reset the quiz – Just call quiz.reset() . Maybe this into the end of the quiz, something like this in (D3) –

DOWNLOAD & NOTES

Here is the download link to the example code, so you don’t have to copy-paste everything.

SUPPORT

600+ free tutorials & projects on Code Boxx and still growing. I insist on not turning Code Boxx into a «paid scripts and courses» business, so every little bit of support helps.

EXAMPLE CODE DOWNLOAD

Click here for the source code on GitHub gist, just click on “download zip” or do a git clone. I have released it under the MIT license, so feel free to build on top of it or use it in your own project.

That’s all for the tutorial, and here is a small section on some extras and links that may be useful to you.

COMPATIBILITY CHECKS

This quiz should work on all modern “Grade A” browsers.

THE END

Thank you for reading, and we have come to the end. I hope that it has helped you to better understand, and if you want to share anything with this guide, please feel free to comment below. Good luck and happy coding!

2 thoughts on “Simple PHP Quiz Without Database (Free Download)”

Hello.
Thank you for this simple quiz, I use this to give my kids and their friends something cool to make when they stay on PC, we make a quiz night every few weeks.
Some suggestions that can make it even more cool:
– add an image for question, so I can add something like “What animal is this?” and show a lion image etc …
-add a timer for every question, eg : 30s pass without any answer, marked at wrong answer and skip to next question
-if refresh the page, quiz should stay on same question, on the left timer ; not starting again with first question.
-life options, for every quiz started you have 3 options like :
+ 50/50 – remove 2 wrong answers
+ skip question – marked as correct answer and skip to next question
+ extra time – add extra seconds to answer to this question

I think it is easy for you to make these changes and updates.
Best Regards,
Cosmin K.

Источник

How to create multiple choice questions and answers in PHP

In this article, you will learn how to create multiple choice quiz questions and answers using the PHP programming language.

Today, online quiz have a lot of advantages. It is considered an easy solution to conduct a quiz, analyse the results, and generate a report. It is also advantageous for the security and confidentiality of quiz questions and answers.

Here, we have created a main PHP file, ‘index.php‘, that we will call in the browser, and have written multiple choice questions and answers using HTML. When the user submits the quiz form, it will redirect to the ‘quiz.php‘ page.

index.php

html> head> title>PHP Multiple Choice Questions and Answers/title> link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> /head> body> div > h1>Multiple Choice Questions Answers/h1> p>Please fill the details and answers the all questions-/p> form action="score.php" method="post"> div > strong>Name*:/strong>br/> input type="text" name="name" value="" required/> /div> div > strong>Age*:/strong>br/> input type="text" name="age" value="" required/> /div> div > strong>Phone*:/strong>br/> input type="text" name="phone" value="" required/> /div> h3>Ques1 : Who is the father of PHP? /h3> div > ol> li> input type="radio" name="q1" value="1" />Rasmus Lerdorf /li> li> input type="radio" name="q1" value="2" />Larry Wall /li> li> input type="radio" name="q1" value="3" />Zeev Suraski /li> /ol> /div> br/> div > h3>Ques2 : Which of the functions is used to sort an array in descending order?/h3> ol> li> input type="radio" name="q2" value="1" />sort() /li> li> input type="radio" name="q2" value="2" />asort() /li> li> input type="radio" name="q2" value="3" />rsort() /li> /ol> /div> br/> div > h3>Ques3 : Which version of PHP introduced the instanceof keyword?/h3> ol> li> input type="radio" name="q3" value="1" />PHP 4 /li> li> input type="radio" name="q3" value="2" />PHP 5 /li> li> input type="radio" name="q3" value="3" />PHP 6 /li> /ol> /div> div > input type="submit" value="Submit" name="submit" /> /div> /form> /div> /body> /html> 

score.php

Next, we have created a PHP page ‘score.php‘ that contains input and multiple choice answers, validation code, and calculates the score level of the user.

?php if($_POST['submit']) < $name = $_POST['name']; $age = $_POST['age']; $phone = $_POST['phone']; if($name == '' || $age == '' || $phone == '') < echo 'h2>Please fill all * mandatory fields./h2>'; > if($q1=='' || $q2 =='' || $q3 =='') $q1 = $_POST['q1']; $q2 = $_POST['q2']; $q3 = $_POST['q3']; if($q1=='' || $q2 =='' || $q3 =='') < echo 'h2>Please answer all questions./h2>'; > else < $score = 0; if($q1 == 1) < // 1st option is correct $score++; >if($q2 == 3) < // 3rd option is correct $score++; >if($q3 == 2) < // 2nd option is correct $score++; >$score = $score / 3 *100; if($score < 50) < echo 'h2>You need to score at least 50% to pass the exam./h2>'; > else < echo 'h2>You have passed the exam and scored '.$score.'%./h2>'; > > > ?>

If the user has filled in all the fields and answered all the questions correctly, it returns the following output.

Источник

Читайте также:  Питон функция умножения матриц
Оцените статью