PHP Operator MCQs
PHP Operator MCQs : This section focuses on "Operator" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.
1. Which of the following is type of operators in PHP?
A. Arithmetic Operators
B. Comparison Operators
C. Assignment Operators
D. All of the above
View Answer
Ans : D
Explanation: PHP language supports following type of operators: Arithmetic Operators, Comparison Operators, Logical (or Relational) Operators, Assignment Operators and Conditional (or ternary) Operators
2. Assume variable A holds 10 and variable B holds 20 then output for Arithmetic Addition Operators is?
A. 10
B. 20
C. 30
D. 40
View Answer
Ans : C
Explanation: A + B will give 30
3. Operator ++ indicate?
A. Decrement operator
B. Increment operator
C. Modulus Operator
D. None of the above
View Answer
Ans : B
Explanation: Operator ++ Increment operator, increases integer value by one.
4. Assume variable A holds 10 and variable B holds 20 then output of A == B is ?
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : B
Explanation: Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true.
5. Operator ? Means?
A. Assignment Operators
B. Modulus AND assignment operator
C. Conditional Operator
D. Divide AND assignment operator
View Answer
Ans : C
Explanation: There is one more operator called conditional operator. This first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation.
6. Associativity of category unary is?
A. Left to right
B. Left to left
C. Right to right
D. Right to left
View Answer
Ans : D
Explanation: Unary has associativity Right to left
7. Logical AND operator : If both the operands are true then condition becomes true.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, Logical AND operator : If both the operands are true then condition becomes true.
8. What will be the output of the following PHP code?
echo $x-- != ++$x;
A. 1
B. 0
C. error
D. no output
View Answer
Ans : A
Explanation: Automatically x is declared and initialized to 0, then decremented and compared with its increments, thus returns 1.
9. What will be the output of the following PHP code?
$y = 2;
if (--$y == 2 || $y xor --$y)
{
echo $y;
}
A. 1
B. 0
C. 2
D. no output
View Answer
Ans : B
Explanation: –$y == 2 is false but y is decremented, the xor gives true if only one of the operands are true, thus 1 xor 0 is true.
10. What will be the output of the following PHP code?
$i = 0;
while(++$i || --$i)
{
print $i;
}
A. 1
B. 01234567891011121314…infinitely
C. 1234567891011121314….infinitely
D. 0
View Answer
Ans : C
Explanation: As it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1.
Discussion