PHP Programming Quiz MCQ!

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Algifanri
A
Algifanri
Community Contributor
Quizzes Created: 1 | Total Attempts: 845
Questions: 15 | Attempts: 845

SettingsSettingsSettings
PHP Programming Quiz MCQ! - Quiz

.


Questions and Answers
  • 1. 

    What will be printed?   if ('2' == '02') { echo 'true'; } else { echo 'false'; }

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    The code compares the string '2' with the string '02'. The double equals (==) operator in PHP performs type coercion, which means it converts the operands to the same type before comparing them. In this case, both strings are converted to integers. Since both '2' and '02' represent the same integer value (2), the comparison returns true. Therefore, the code will print 'true'.

    Rate this question:

  • 2. 

    Which of the following is NOT a valid pHP comparison operator?

    • A.

      !=

    • B.

      >=

    • C.

    • D.

    • E.

      ===

    Correct Answer
    C.
    Explanation
    The comparison operators in PHP are used to compare two values and determine their relationship. The "!=" operator is a valid comparison operator in PHP and it checks if two values are not equal. The ">=" operator is also a valid comparison operator and it checks if the left operand is greater than or equal to the right operand. The "===" operator is another valid comparison operator in PHP and it checks if two values are identical in terms of both value and data type. Therefore, the answer is not available.

    Rate this question:

  • 3. 

    What will be printed?   $a = array( null => 'a', true => 'b', false => 'c', 0 => 'd', 1 => 'e', '' => 'f' ); echo count($a), "\n";

    • A.

      2

    • B.

      3

    • C.

      4

    • D.

      5

    • E.

      6

    Correct Answer
    B. 3
    Explanation
    Keys will be converted like this: null to '' (empty string), true to 1, false to 0

    Rate this question:

  • 4. 

    What gets printed?   class MyException extends Exception {} try { throw new MyException('Oops!'); } catch (Exception $e) { echo "Caught Exception\n"; } catch (MyException $e) { echo "Caught MyException\n"; }

    • A.

      Caught Exception

    • B.

      Caught MyException

    Correct Answer
    A. Caught Exception
    Explanation
    The first catch will match because MyException is a subclass of Exception, so the second catch is unreachable.

    Rate this question:

  • 5. 

    What will be printed?$a = array();if ($a[1]) null;echo count($a), "\n";

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      This code wont compile

    Correct Answer
    A. 0
    Explanation
    checking the value in if() does not create an array element.

    Rate this question:

  • 6. 

    What gets printed?   $str = 'a\\b\n'; echo $str;

    • A.

      Ab(newline)

    • B.

      A\b(newline)

    • C.

      A\b\n

    • D.

      A\\b(newline)

    • E.

      A\\b\n

    Correct Answer
    C. A\b\n
    Explanation
    \\ is a special case in single-quoted string literals, which gives a single \, \n is not interpolated in single-quoted string literals.

    Rate this question:

  • 7. 

    What is the correct way of defining constants in pHP?

    • A.

      Constant $var

    • B.

      Const $var

    • C.

      Constant ($var)

    • D.

      Define("Constant");

    Correct Answer
    D. Define("Constant");
    Explanation
    The correct way of defining constants in PHP is by using the define() function. This function takes two parameters: the name of the constant and its value. In this case, the constant is defined as "Constant" without a value, which means it will be an empty constant.

    Rate this question:

  • 8. 

    Which function will you use to convert an HTML page into a format that can be saved in the database conveniently?

    • A.

      Stripslashes()

    • B.

      Htmlentities()

    • C.

      Htmlspecialchars()

    Correct Answer
    B. Htmlentities()
    Explanation
    The htmlentities() function is used to convert special characters in an HTML page into their corresponding HTML entities. This ensures that the HTML code is properly encoded and can be safely stored in a database without causing any syntax or formatting issues. By using htmlentities(), the HTML page can be converted into a format that can be conveniently saved in the database, preserving the integrity of the original content.

    Rate this question:

  • 9. 

    Which of the following functions will be used to create CURL sessions?

    • A.

      Curl_exec()

    • B.

      Curl_opt()

    • C.

      Curl_init()

    • D.

      Curl_setopt()

    Correct Answer
    C. Curl_init()
    Explanation
    The correct answer is curl_init(). This function is used to initialize a new CURL session. It returns a CURL handle, which is then used in other CURL functions to perform various operations like setting options, executing the request, etc. curl_exec() is used to execute the CURL request, curl_opt() is not a valid CURL function, and curl_setopt() is used to set various options for the CURL session.

    Rate this question:

  • 10. 

    Which of the following is true about GET & POST methods?

    • A.

      GET will not show variables in URL of address bar of browser

    • B.

      POST variables can not be accessed by $_REQUEST[] Server side array

    • C.

      Using POST, you can hide form data from being viewed on address bar or browser

    Correct Answer
    C. Using POST, you can hide form data from being viewed on address bar or browser
    Explanation
    The correct answer is that using POST, you can hide form data from being viewed on the address bar or browser. This is because when using the POST method, the data is sent in the body of the HTTP request, rather than being appended to the URL like in the GET method. Therefore, the form data is not visible in the address bar or browser history.

    Rate this question:

  • 11. 

    Which of the following statements will be used to fetch SINGLE record  from a MySql resultset

    • A.

      Mysql_connect

    • B.

      Mysql_query

    • C.

      Mysql_fetch_array

    • D.

      Mysql_fetch_row

    Correct Answer
    D. Mysql_fetch_row
    Explanation
    The correct answer is mysql_fetch_row. This function is used to fetch a single row from a MySQL result set as an enumerated array. It returns an array that corresponds to the fetched row, or false if there are no more rows in the result set. This function is commonly used when you only need to retrieve a single record from the result set.

    Rate this question:

  • 12. 

    What is the correct syntax for connecting to a MySql database?

    • A.

      Mysql_connect($username,$password)

    • B.

      Connect_mysql($username,$password)

    • C.

      Mysql_connect("localhost",$username,$password)

    Correct Answer
    C. Mysql_connect("localhost",$username,$password)
    Explanation
    The correct syntax for connecting to a MySql database is "mysql_connect("localhost",$username,$password)". This syntax specifies the host as "localhost" and requires the username and password parameters to establish a connection with the MySql database.

    Rate this question:

  • 13. 

    Which of the following functions MUST be called AFTER using the mysql_connect() function?

    • A.

      Mysql_query

    • B.

      Mysql_fetch_array

    • C.

      Mysql_select_db

    • D.

      Mysql_fetch_row

    Correct Answer
    C. Mysql_select_db
    Explanation
    The mysql_select_db function must be called after using the mysql_connect function because it is used to select a specific database to work with. After establishing a connection with the database using mysql_connect, it is necessary to select the database that will be queried or manipulated using mysql_select_db. This function allows the user to specify the database name as a parameter, ensuring that all subsequent queries and operations are performed on the selected database.

    Rate this question:

  • 14. 

    What gets printed?   <?php $RESULT = 11 + 011 + 0x11; echo "$RESULT"; ?>

    • A.

      11

    • B.

      22

    • C.

      33

    • D.

      37

    • E.

      39

    Correct Answer
    D. 37
    Explanation
    A decimal plus an octal plus a hex number. 11 + 9 + 17 = 37

    Rate this question:

  • 15. 

    What will be the value of $var below?   $var = true ? '1' : false ? '2' : '3';

    • A.

      1

    • B.

      2

    • C.

      3

    Correct Answer
    B. 2
    Explanation
    The value of $var will be 2. This is because the expression is using the ternary operator, which is a shorthand way of writing an if-else statement. In this case, the first condition "true ? '1' : false" evaluates to true, so the value '1' is returned. Then, the second condition "1 ? '2' : '3'" evaluates to true, so the value '2' is returned and assigned to $var.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Aug 02, 2019
    Quiz Created by
    Algifanri
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.