Home »
Aptitude Questions and Answers »
PHP Aptitude Questions and Answers
PHP Operators Aptitude Questions and Answers
PHP Operators Aptitude Questions and Answers: This section contains aptitude questions and answers on PHP Operators.
By Nidhi Last updated : December 15, 2023
This section contains Aptitude Questions and Answers on PHP Operators.
1) Which of the following types of operators are used in PHP?
- Arithmetic Operators
- Logical Operators
- Array Operators
- String Operators
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All given options are correct types of operators are used in PHP.
2) What is the correct output of the given code snippets?
<?php
$NUM1 = 3;
$NUM2 = 4;
$NUM3 = $NUM1 ** $NUM2;
echo $NUM3;
?>
- 12
- 81
- Garbage value
- None of the above
Correct answer: 2
81
The above code will print "81" on the webpage. Because ** operator is used for exponential.
3) The "**" operator belongs to which category of operators?
- Arithmetic operator
- Logical operator
- Comparison operator
- Conditional operator
Correct answer: 1
Arithmetic operator
The ** operator belongs to arithmetic operators.
4) Which of the following are comparison operators in PHP?
- ==
- !=
- ===
- < = >
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All the given options are comparison operators.
5) What is the correct output of given code snippets?
<?php
$NUM1 = 3;
$NUM2 = 4;
var_dump($NUM1 != $NUM2);
?>
- bool(true)
- bool(false)
- Error
- None of the above
Correct answer: 1
bool(true)
The above code will print bool(true) on the webpage, the <> operator is "not equal to" operator.
6) What is the correct output of given code snippets?
<?php
$NUM1 = 3;
$NUM2 = 4;
var_dump($NUM1 !== $NUM2);
?>
- bool(true)
- bool(false)
- Error
- None of the above
Correct answer: 1
bool(true)
The above code will print bool(true) on the webpage.
7) What is the correct output of given code snippets?
<?php
$NUM1 = 3;
$NUM2 = 4;
var_dump($NUM1 <=> $NUM2);
?>
- int(0)
- int(-1)
- int(1)
- Error
Correct answer: 2
int(-1)
The above code will print "int(-1)" on the webpage.
8) Which of the following operator is not available in PHP?
<?php
$num = "Hello";
var_dump($num);
?>
- Dot (.)
- =
- .=
- @
Correct answer: 4
@
The @ operator is not available in PHP.
9) What is the correct output of given code snippets?
<?php
echo $country = $country ?? "india";
?>
- india
- garbage value
- Error
- None of the above
Correct answer: 1
india
The above code will print the "india" on the webpage.
10) Which of the following operator is known as null coalescing in PHP?
- < == >
- ===
- ??
- ?
Correct answer: 3
??
The ?? operator is known as the null coalescing operator in PHP.