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");
Answer (Detailed Solution Below)
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 number25
- Hence,
25 == 25
results intrue
- JavaScript converts the string
- Similarly,
92 == "92"
also returnstrue
due to type coercion.
Additional Information
- If we used
===
(strict equality), then:25 === "25"
would returnfalse
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;
Answer (Detailed Solution Below)
PHP etc Question 2 Detailed Solution
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?
Answer (Detailed Solution Below)
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 variablex
.var y = 30;
var y = "Hi";
✅ Allowed: No error due to redeclaration ofy
.
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
andconst
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);
Answer (Detailed Solution Below)
PHP etc Question 4 Detailed Solution
Correct Option: 3) [2, 3]
- An array in PHP is a collection of values, which can be of different data types such as strings, integers, and other arrays.
- Each value in an array is assigned a key or index, starting from 0 and incrementing by 1 for each subsequent value.
- PHP arrays can be indexed by integers or strings, and can be either indexed or associative.
- Indexed arrays use numeric keys, while associative arrays use string keys.
- Arrays in PHP can be created using the array() function or by using square brackets [], as shown in the code example.
- 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";
}
Answer (Detailed Solution Below)
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
- In PHP, echo is a language construct used to output data to the browser or to a file.
- It is used to display text or other content on a web page or to send text to other programs or files.
- 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?
Answer (Detailed Solution Below)
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?
Answer (Detailed Solution Below)
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.
- 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?
Answer (Detailed Solution Below)
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";
}
?>
Answer (Detailed Solution Below)
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?
Answer (Detailed Solution Below)
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";
}
Answer (Detailed Solution Below)
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
- In PHP, echo is a language construct used to output data to the browser or to a file.
- It is used to display text or other content on a web page or to send text to other programs or files.
- 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 _____
Answer (Detailed Solution Below)
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");
Answer (Detailed Solution Below)
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 number25
- Hence,
25 == 25
results intrue
- JavaScript converts the string
- Similarly,
92 == "92"
also returnstrue
due to type coercion.
Additional Information
- If we used
===
(strict equality), then:25 === "25"
would returnfalse
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;
Answer (Detailed Solution Below)
PHP etc Question 14 Detailed Solution
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?
Answer (Detailed Solution Below)
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 variablex
.var y = 30;
var y = "Hi";
✅ Allowed: No error due to redeclaration ofy
.
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
andconst
to avoid scope-related issues.