PHP etc MCQ Quiz - Objective Question with Answer for PHP etc - Download Free PDF

Last updated on Jun 27, 2025

Latest PHP etc MCQ Objective Questions

PHP etc Question 1:

What will be the output of the follwing Javascript code snippet?
console.log(25= "25");
console.log(92 "92");

  1. false
  2. Error: Cannot use for comparison
  3. false
    true
  4. true
    true

Answer (Detailed Solution Below)

Option 4 : true
true

PHP etc Question 1 Detailed Solution

The correct answer is Option 4) true true.

Key Points

  • == is a loose equality operator in JavaScript.
  • It compares two values for equality after converting both values to a common type (type coercion).
  • In the expression 25 == "25":
    • JavaScript converts the string "25" to number 25
    • Hence, 25 == 25 results in true
  • Similarly, 92 == "92" also returns true due to type coercion.

Additional Information

  • If we used === (strict equality), then:
    • 25 === "25" would return false since number and string types don’t match.
  • For type-safe comparison, use === instead of == to avoid unexpected results due to type coercion.

Conclusion: Both statements return true because of JavaScript's type coercion using the == operator.

PHP etc Question 2:

What will be the value of y on executing the follwing Javascript code snippet?
let x = 3;
let y = x **=2;

  1. 9
  2. Error: **= is an invalid operator
  3. 3 * 2 * 2
  4. 3 * 3 * 2

Answer (Detailed Solution Below)

Option 1 : 9

PHP etc Question 2 Detailed Solution

The correct answer is Option 1) 9.
Key Points
The expression uses the exponentiation assignment operator **=, which is valid in JavaScript (introduced in ECMAScript 2016).
let x = 3; → initializes variable x with value 3.
x **= 2; → is equivalent to x = x ** 2; → 3 ** 2 = 9.
let y = x **= 2; means the result of x **= 2 (which is 9) is assigned to y as well.
So, both x and y become 9.
 
Additional Information 
Option 2 – Incorrect: **= is a valid operator in JavaScript, not an error.
Option 3 – Incorrect: 3 * 2 * 2 = 12, which is unrelated to exponentiation logic.
Option 4 – Incorrect: 3 * 3 * 2 = 18 is also incorrect — the exponentiation used is 3^2, not multiplied again by 2.
Exponentiation Operator **:
a ** b means a raised to the power b.
**= is the shorthand for variable = variable ** value.

PHP etc Question 3:

Consider the following JavaScript code snippet:
let x = 10
let x = "Hello"
var y = 30
var y = "Hi"
Which of the following statement is correct?

  1. Variable x and y both cannot be redeclared.
  2. Variable x and y both can be redeclared.
  3. Variable x cannot be redeclared, variable y can be redeclared.
  4. Variable x can be redeclared, variable y cannot be redeclared.

Answer (Detailed Solution Below)

Option 3 : Variable x cannot be redeclared, variable y can be redeclared.

PHP etc Question 3 Detailed Solution

The correct answer is Option 3) Variable x cannot be redeclared, variable y can be redeclared.

Key Points

  • In JavaScript:
    • let and const declarations cannot be redeclared in the same scope.
    • var declarations can be redeclared in the same scope without causing an error.
  • Therefore:
    • let x = 10;
      let x = "Hello";Error: Cannot redeclare variable x.
    • var y = 30;
      var y = "Hi";Allowed: No error due to redeclaration of y.

Additional Information 

  • let and const were introduced in ES6 to improve variable scoping and reduce bugs from unintended redeclarations.
  • var has function-level scoping and allows hoisting, which can lead to logical errors if not handled properly.
  • Best practice in modern JavaScript is to use let and const to avoid scope-related issues.

PHP etc Question 4:

What will be the output of the following PHP code?

$arr1 = [1, 2, 3];
$arr2 = [2, 3, 4];
$result = array_intersect($arr1, $arr2);
print_r($result);

  1.  [1, 2, 3]
  2.  [2, 3, 4]
  3.  [2, 3]
  4.  []

Answer (Detailed Solution Below)

Option 3 :  [2, 3]

PHP etc Question 4 Detailed Solution

Correct Option: 3) [2, 3]

  1. An array in PHP is a collection of values, which can be of different data types such as strings, integers, and other arrays.
  2. Each value in an array is assigned a key or index, starting from 0 and incrementing by 1 for each subsequent value.
  3. PHP arrays can be indexed by integers or strings, and can be either indexed or associative.
  4. Indexed arrays use numeric keys, while associative arrays use string keys.
  5. Arrays in PHP can be created using the array() function or by using square brackets [], as shown in the code example.
  6. Additionally, there are many built-in functions in PHP for manipulating arrays, such as array_intersect(), array_merge(), array_push(), and array_pop(), among others.

Explanation:

  • The array_intersect() function is used to find the common elements between two or more arrays.
  • In the given code, two arrays $arr1 and $arr2 are defined with values [1, 2, 3] and [2, 3, 4] respectively.
  • The array_intersect() function is then called with $arr1 and $arr2 as arguments, which finds the common elements between the two arrays.
  • In this case, the common elements are 2 and 3. The resulting array contains these common elements with their corresponding keys from the first array.
  • ​Finally, the resulting array is printed using print_r(), which outputs: [2, 3].

PHP etc Question 5:

What will be the output of the following PHP code?
$num = 15;
$str = "15";
if ($num == $str) {
    echo "Equal";
} else {
    echo "Not Equal";
}

  1. Equal
  2. Not Equal
  3. Error
  4. None of the above

Answer (Detailed Solution Below)

Option 1 : Equal

PHP etc Question 5 Detailed Solution

Correct Option: 1) Equal

  • The output of the code will be "Equal".
  • In the code, the $num variable is assigned an integer value of 15, and the $str variable is assigned a string value of "15".
  • The == operator is used to compare the values of the two variables. This operator checks if the values are equal, regardless of their data type.
  • Since both variables have the same value of 15, the condition in the if statement evaluates to true, and the "Equal" string is printed to the output.
  • It's important to note that the == operator only checks for value equality, while the === operator checks for both value and type equality. If the === operator were used in the code instead of the == operator, the output would be "Not Equal" since the types of $num and $str are different.
  • In PHP, the double equals (==) operator performs type coercion, converting operands to the same type before comparing them for equality.
  • In this code snippet, the variable $num is compared to the string "15", which is converted to an integer 15 before the comparison.
  • Since the values are equal, the if statement evaluates to true and the output will be "Equal"

PHP, echo

  1. In PHP, echo is a language construct used to output data to the browser or to a file.
  2. It is used to display text or other content on a web page or to send text to other programs or files.
  3. The syntax for using echo is straightforward: just type the keyword followed by the content that you want to output, enclosed in quotes or without quotes if the content is a variable or a constant.

Examples of using echo:

/ Output a simple string
echo "Hello, world!";

/ Output the value of a variable
$name = "John";
echo "My name is " . $name;

/ Output HTML markup
echo "

Welcome to my website

";

Top PHP etc MCQ Objective Questions

PHP etc Question 6:

Which protocol is used for requesting a web page in ASP.NET from the Web Server?

  1. SMTP
  2. TCP 
  3. FTP
  4. HTTP

Answer (Detailed Solution Below)

Option 4 : HTTP

PHP etc Question 6 Detailed Solution

HTTP protocol is used for requesting a web page in ASP.NET from the Web Server:

Important Point of HTTP

  • The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems.
  • HTTP is the foundation of data communication for the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily access.

PHP etc Question 7:

Which of the following is a server side scripting language?

  1. HTML
  2. DHTML
  3. XML
  4. PHP
  5. None of these

Answer (Detailed Solution Below)

Option 4 : PHP

PHP etc Question 7 Detailed Solution

The correct answer is PHP

Important Points

  • Server-side scripting is a method of designing websites so that the process or user request is run on the originating server. Server-side scripts provide an interface to the user and limit access to proprietary data and help keep control of the script source code. Below is an example of client-side scripts vs. server-side scripts.

 

Key Points

  • Many languages may be used to create these scripts. They include but are not limited to the examples below:
    • ActiveVFP
    • ASP
    • C
    • DC
    • Java
    • JavaScript (using SSJS (Server-side JavaScript) e.g., node.js)
    • Perl
    • PHP
    • Python
    • R
    • Ruby

PHP etc Question 8:

Consider the code given below

function EDUTECH() 

{

function TESTBOOK()

          {

            echo 'TESTBOOK';

 }

        echo ' EDUTECH';

}

TESTBOOK();

EDUTECH();

?>

What is the output?

  1. EDUTECH
  2. TESTBOOK EDUTECH
  3. EDUTECH TESTBOOK
  4. Error

Answer (Detailed Solution Below)

Option 4 : Error

PHP etc Question 8 Detailed Solution

  • The code will throw fatal error: Call to undefined TESTBOOK();
  • Coder cannot call a function which is inside a function without calling the outside function first.

PHP etc Question 9:

What will be the output of the following PHP code?

for ($x = 5; 0; $x--)

{

    print"x";

}

?>

  1. prints the value from 5 to 1
  2. loop runs infinite
  3. Error in code
  4. no output

Answer (Detailed Solution Below)

Option 4 : no output

PHP etc Question 9 Detailed Solution

for ($x = 5; 0; $x--)

Conditional statement in for loop is 0 which means false. Since Condition of loop is always false (0) and therefore there will be no output.

PHP etc Question 10:

What is a magic method in PHP?

  1. Method that start with _ (underscore)
  2. Method that start with $ (dollar)
  3. Method that start with __ (double underscore)
  4. Method that start with @ (at the rate)

Answer (Detailed Solution Below)

Option 3 : Method that start with __ (double underscore)

PHP etc Question 10 Detailed Solution

  • PHP functions that start with a double __ (underscore) are called magic method (or functions).
  • They are functions that are always defined inside classes and are not stand-alone (outside of classes) functions.
  •  The magic functions available in PHP are: __construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(), __sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone(), and __autoload().

PHP etc Question 11:

What will be the output of the following PHP code?
$num = 15;
$str = "15";
if ($num == $str) {
    echo "Equal";
} else {
    echo "Not Equal";
}

  1. Equal
  2. Not Equal
  3. Error
  4. None of the above

Answer (Detailed Solution Below)

Option 1 : Equal

PHP etc Question 11 Detailed Solution

Correct Option: 1) Equal

  • The output of the code will be "Equal".
  • In the code, the $num variable is assigned an integer value of 15, and the $str variable is assigned a string value of "15".
  • The == operator is used to compare the values of the two variables. This operator checks if the values are equal, regardless of their data type.
  • Since both variables have the same value of 15, the condition in the if statement evaluates to true, and the "Equal" string is printed to the output.
  • It's important to note that the == operator only checks for value equality, while the === operator checks for both value and type equality. If the === operator were used in the code instead of the == operator, the output would be "Not Equal" since the types of $num and $str are different.
  • In PHP, the double equals (==) operator performs type coercion, converting operands to the same type before comparing them for equality.
  • In this code snippet, the variable $num is compared to the string "15", which is converted to an integer 15 before the comparison.
  • Since the values are equal, the if statement evaluates to true and the output will be "Equal"

PHP, echo

  1. In PHP, echo is a language construct used to output data to the browser or to a file.
  2. It is used to display text or other content on a web page or to send text to other programs or files.
  3. The syntax for using echo is straightforward: just type the keyword followed by the content that you want to output, enclosed in quotes or without quotes if the content is a variable or a constant.

Examples of using echo:

/ Output a simple string
echo "Hello, world!";

/ Output the value of a variable
$name = "John";
echo "My name is " . $name;

/ Output HTML markup
echo "

Welcome to my website

";

PHP etc Question 12:

In ASP.NET, Application_Start event is available in _____

  1. Global.asp
  2. Local.asp
  3. Global.asax
  4. Local.asax

Answer (Detailed Solution Below)

Option 3 : Global.asax

PHP etc Question 12 Detailed Solution

  • Application_Start: Called when the first resource (such as a page) in an ASP.NET application is requested.
  • The Application_Start method is called only one time during the life cycle of an application. User can use this method to perform startup tasks such as loading data into the cache and initializing static values.
  • Application_Start event is available in Global.asax

PHP etc Question 13:

What will be the output of the follwing Javascript code snippet?
console.log(25= "25");
console.log(92 "92");

  1. false
  2. Error: Cannot use for comparison
  3. false
    true
  4. true
    true

Answer (Detailed Solution Below)

Option 4 : true
true

PHP etc Question 13 Detailed Solution

The correct answer is Option 4) true true.

Key Points

  • == is a loose equality operator in JavaScript.
  • It compares two values for equality after converting both values to a common type (type coercion).
  • In the expression 25 == "25":
    • JavaScript converts the string "25" to number 25
    • Hence, 25 == 25 results in true
  • Similarly, 92 == "92" also returns true due to type coercion.

Additional Information

  • If we used === (strict equality), then:
    • 25 === "25" would return false since number and string types don’t match.
  • For type-safe comparison, use === instead of == to avoid unexpected results due to type coercion.

Conclusion: Both statements return true because of JavaScript's type coercion using the == operator.

PHP etc Question 14:

What will be the value of y on executing the follwing Javascript code snippet?
let x = 3;
let y = x **=2;

  1. 9
  2. Error: **= is an invalid operator
  3. 3 * 2 * 2
  4. 3 * 3 * 2

Answer (Detailed Solution Below)

Option 1 : 9

PHP etc Question 14 Detailed Solution

The correct answer is Option 1) 9.
Key Points
The expression uses the exponentiation assignment operator **=, which is valid in JavaScript (introduced in ECMAScript 2016).
let x = 3; → initializes variable x with value 3.
x **= 2; → is equivalent to x = x ** 2; → 3 ** 2 = 9.
let y = x **= 2; means the result of x **= 2 (which is 9) is assigned to y as well.
So, both x and y become 9.
 
Additional Information 
Option 2 – Incorrect: **= is a valid operator in JavaScript, not an error.
Option 3 – Incorrect: 3 * 2 * 2 = 12, which is unrelated to exponentiation logic.
Option 4 – Incorrect: 3 * 3 * 2 = 18 is also incorrect — the exponentiation used is 3^2, not multiplied again by 2.
Exponentiation Operator **:
a ** b means a raised to the power b.
**= is the shorthand for variable = variable ** value.

PHP etc Question 15:

Consider the following JavaScript code snippet:
let x = 10
let x = "Hello"
var y = 30
var y = "Hi"
Which of the following statement is correct?

  1. Variable x and y both cannot be redeclared.
  2. Variable x and y both can be redeclared.
  3. Variable x cannot be redeclared, variable y can be redeclared.
  4. Variable x can be redeclared, variable y cannot be redeclared.

Answer (Detailed Solution Below)

Option 3 : Variable x cannot be redeclared, variable y can be redeclared.

PHP etc Question 15 Detailed Solution

The correct answer is Option 3) Variable x cannot be redeclared, variable y can be redeclared.

Key Points

  • In JavaScript:
    • let and const declarations cannot be redeclared in the same scope.
    • var declarations can be redeclared in the same scope without causing an error.
  • Therefore:
    • let x = 10;
      let x = "Hello";Error: Cannot redeclare variable x.
    • var y = 30;
      var y = "Hi";Allowed: No error due to redeclaration of y.

Additional Information 

  • let and const were introduced in ES6 to improve variable scoping and reduce bugs from unintended redeclarations.
  • var has function-level scoping and allows hoisting, which can lead to logical errors if not handled properly.
  • Best practice in modern JavaScript is to use let and const to avoid scope-related issues.

Hot Links: teen patti real money app teen patti online teen patti party teen patti all app