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?
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?
Explanation: A + B will give 30
3. Operator ++ indicate?
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 ?
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?
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?
Explanation: Unary has associativity Right to left
7. Logical AND operator : If both the operands are true then condition becomes true.
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;
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)
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)
Explanation: As it is || operator the second expression is not evaluated and i is always incremented, in the first case to 1.