PHP Programming Quiz MCQ!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Algifanri
A
Algifanri
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,015
| Attempts: 1,015 | Questions: 15
Please wait...
Question 1 / 15
0 %
0/100
Score 0/100
1. Which of the following is true about GET & POST methods?

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.

Submit
Please wait...
About This Quiz
PHP Programming Quiz MCQ! - Quiz

The 'PHP Programming Quiz MCQ!' assesses knowledge of PHP syntax and behavior through multiple-choice questions. It covers comparisons, array manipulations, exception handling, and string operations, suitable for learners... see moreaiming to enhance their PHP programming skills. see less

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

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.

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

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'.

Submit
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";


}

Explanation

The first catch will match because MyException is a subclass of Exception, so the second catch is unreachable.

Submit
5. What is the correct way of defining constants in PHP?

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.

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

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.

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

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.

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

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.

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

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.

Submit
10. Which of the following is NOT a valid PHP comparison operator?

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.

Submit
11. What will be printed?

$a = array();

if ($a[1]) null;

echo count($a), "\n";

Explanation

checking the value in if() does not create an array element.

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

Explanation

\\ is a special case in single-quoted string literals, which gives a single \, \n is not interpolated in single-quoted string literals.

Submit
13. What will be printed?  
$a = array(
 null => 'a',
 true => 'b',
 false => 'c',
 0 => 'd',
 1 => 'e',
 '' => 'f'
);

echo count($a), "\n";

Explanation

Keys will be converted like this: null to '' (empty string), true to 1, false to 0

Submit
14. What gets printed?  
<?php

$RESULT = 11 + 011 + 0x11;

echo "$RESULT";

?>

Explanation

A decimal plus an octal plus a hex number. 11 + 9 + 17 = 37

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

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
Cancel
  • All
    All (15)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Which of the following is true about GET & POST methods?
What is the correct syntax for connecting to a MySql database?
What will be printed?...
What gets printed?...
What is the correct way of defining constants in PHP?
Which of the following functions will be used to create CURL sessions?
Which of the following functions MUST be called AFTER using the...
Which function will you use to convert an HTML page into a format that...
Which of the following statements will be used to fetch SINGLE...
Which of the following is NOT a valid PHP comparison operator?
What will be printed?$a = array();if ($a[1]) null;echo count($a),...
What gets printed?   $str = 'a\\b\n'; echo $str;
What will be printed?...
What gets printed?...
What will be the value of $var below?...
Alert!

Advertisement