MCQs on Operators | PHP Basics

Unlock your PHP expertise with this comprehensive set of 30 multiple-choice questions focused on PHP operators. Delve into the world of Arithmetic, Comparison, Logical, Assignment, Increment/Decrement, and String Operators, and solidify your understanding of PHP programming fundamentals. Perfect for developers looking to master PHP for web development projects.


Topic 1: Arithmetic Operators (5 Questions)

  1. What will be the output of the following PHP code?phpCopy codeecho 15 % 4; A) 3
    B) 4
    C) 15
    D) 1
  2. Which operator is used for exponentiation in PHP?
    A) ^
    B) **
    C) ^^
    D) exp()
  3. What will be the result of the expression 10 + 5 * 2 in PHP?
    A) 30
    B) 20
    C) 25
    D) 40
  4. How can you divide two numbers in PHP?
    A) Using //
    B) Using /
    C) Using %
    D) Using div
  5. What will the following code output?phpCopy code$a = 7; $b = 2; echo $a / $b; A) 3
    B) 3.5
    C) 2
    D) 7.0

Topic 2: Comparison Operators (5 Questions)

  1. Which operator checks if two variables are equal in value and type?
    A) ==
    B) ===
    C) !=
    D) <=
  2. What does the expression $a != $b mean in PHP?
    A) $a is equal to $b
    B) $a is not equal to $b
    C) $a is less than $b
    D) $a is greater than $b
  3. How do you check if a value is greater than or equal to another value?
    A) =<
    B) =>
    C) >=
    D) =>=
  4. What will be the output of the following code?phpCopy codeecho (5 == '5') ? 'True' : 'False'; A) True
    B) False
    C) Error
    D) Null
  5. Which operator checks if a variable is not identical (different type or value)?
    A) !==
    B) !=
    C) ===
    D) ==

Topic 3: Logical Operators (5 Questions)

  1. Which logical operator is used to combine conditions where both must be true?
    A) ||
    B) &&
    C) and
    D) or
  2. What does the expression !false return?
    A) True
    B) False
    C) Null
    D) 1
  3. How would you check if either condition A or condition B is true in PHP?
    A) A || B
    B) A && B
    C) A & B
    D) A | B
  4. What will the following expression output?phpCopy codeecho (true && false) ? 'Yes' : 'No'; A) Yes
    B) No
    C) Error
    D) True
  5. Which operator has higher precedence, && or ||?
    A) &&
    B) ||
    C) Both have the same
    D) Depends on the context

Topic 4: Assignment Operators (5 Questions)

  1. What does the expression $a += 5 mean?
    A) $a = $a + 5
    B) $a = 5
    C) $a = $a * 5
    D) $a + 5 = 0
  2. Which assignment operator is used to concatenate strings?
    A) .=
    B) ++
    C) ==
    D) +=
  3. How can you decrease a variable by 3 in PHP?
    A) $var -= 3
    B) $var =- 3
    C) $var = 3-
    D) $var := 3
  4. What does the expression $b *= 3 do?
    A) Multiplies $b by 3
    B) Divides $b by 3
    C) Adds 3 to $b
    D) Sets $b to 3
  5. Which operator is used to assign by reference?
    A) =>
    B) ==
    C) &=
    D) = &

Topic 5: Increment/Decrement Operators (5 Questions)

  1. What does $x++ do in PHP?
    A) Decreases $x by 1
    B) Increases $x by 1
    C) Returns $x + 1 without changing $x
    D) Returns $x – 1 without changing $x
  2. What will be the value of $y after this code?phpCopy code$y = 10; $y--; A) 11
    B) 10
    C) 9
    D) 0
  3. Which of the following is the correct way to decrement a variable?
    A) var++
    B) –var
    C) var–
    D) ++var
  4. What will the following code output?phpCopy code$a = 5; echo ++$a; A) 5
    B) 6
    C) 4
    D) 7
  5. What happens when you use --$x in PHP?
    A) The value is increased by 1
    B) The value is decreased by 1
    C) No change
    D) Sets $x to 0

Topic 6: String Operators (5 Questions)

  1. Which operator is used to concatenate two strings in PHP?
    A) +
    B) .
    C) ,
    D) &
  2. What does the expression $str1 .= $str2 do?
    A) Assigns $str2 to $str1
    B) Adds $str2 to $str1
    C) Concatenates $str2 to $str1
    D) Compares $str1 and $str2
  3. How would you append a string to an existing variable in PHP?
    A) .=
    B) =.
    C) +=
    D) ==
  4. What is the result of the following code?phpCopy code$text = "Hello"; $text .= " World"; echo $text; A) Hello
    B) HelloWorld
    C) Hello World
    D) World
  5. What will $var1 . $var2 output if $var1 = "PHP" and $var2 = "Rocks"?
    A) PHP Rocks
    B) PHPRocks
    C) PHP.Rocks
    D) PHP-Rocks

Answer Key

QnoAnswer (Option with the text)
1A) 3
2B) **
3C) 25
4B) Using /
5B) 3.5
6B) ===
7B) $a is not equal to $b
8C) >=
9A) True
10A) !==
11B) &&
12A) True
13A) A
14B) No
15A) &&
16A) $a = $a + 5
17A) .=
18A) $var -= 3
19A) Multiplies $b by 3
20D) = &
21B) Increases $x by 1
22C) 9
23C) var–
24B) 6
25B) The value is decreased by 1
26B) .
27C) Concatenates $str2 to $str1
28A) .=
29C) Hello World
30B) PHPRocks

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top