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)
What will be the output of the following PHP code?phpCopy codeecho 15 % 4; A) 3 B) 4 C) 15 D) 1
Which operator is used for exponentiation in PHP? A) ^ B) ** C) ^^ D) exp()
What will be the result of the expression 10 + 5 * 2 in PHP? A) 30 B) 20 C) 25 D) 40
How can you divide two numbers in PHP? A) Using // B) Using / C) Using % D) Using div
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)
Which operator checks if two variables are equal in value and type? A) == B) === C) != D) <=
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
How do you check if a value is greater than or equal to another value? A) =< B) => C) >= D) =>=
What will be the output of the following code?phpCopy codeecho (5 == '5') ? 'True' : 'False'; A) True B) False C) Error D) Null
Which operator checks if a variable is not identical (different type or value)? A) !== B) != C) === D) ==
Topic 3: Logical Operators (5 Questions)
Which logical operator is used to combine conditions where both must be true? A) || B) && C) and D) or
What does the expression !false return? A) True B) False C) Null D) 1
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
What will the following expression output?phpCopy codeecho (true && false) ? 'Yes' : 'No'; A) Yes B) No C) Error D) True
Which operator has higher precedence, && or ||? A) && B) || C) Both have the same D) Depends on the context
Topic 4: Assignment Operators (5 Questions)
What does the expression $a += 5 mean? A) $a = $a + 5 B) $a = 5 C) $a = $a * 5 D) $a + 5 = 0
Which assignment operator is used to concatenate strings? A) .= B) ++ C) == D) +=
How can you decrease a variable by 3 in PHP? A) $var -= 3 B) $var =- 3 C) $var = 3- D) $var := 3
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
Which operator is used to assign by reference? A) => B) == C) &= D) = &
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
What will be the value of $y after this code?phpCopy code$y = 10; $y--; A) 11 B) 10 C) 9 D) 0
Which of the following is the correct way to decrement a variable? A) var++ B) –var C) var– D) ++var
What will the following code output?phpCopy code$a = 5; echo ++$a; A) 5 B) 6 C) 4 D) 7
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)
Which operator is used to concatenate two strings in PHP? A) + B) . C) , D) &
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
How would you append a string to an existing variable in PHP? A) .= B) =. C) += D) ==
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
What will $var1 . $var2 output if $var1 = "PHP" and $var2 = "Rocks"? A) PHP Rocks B) PHPRocks C) PHP.Rocks D) PHP-Rocks