Best 20+ multiple-choice questions (MCQs) on PHP Data Types and related topics. The questions are designed to test your knowledge and understanding of PHP data types, operators, and their behaviors. Each question is followed by four options and the correct answer is highlighted for each question. This content is useful for anyone who wants to test their knowledge of PHP data types or prepare for PHP certification exams.

Contents hide

Question 1: What is the output of the following PHP code snippet?

$var1 = "hello";
$var2 = 5;
echo gettype($var1) . " " . gettype($var2);
  • string integer
  • integer string
  • string string
  • integer integer


Question 2: What is the data type of the value returned by the PHP function strpos()?

  • integer
  • string
  • array
  • boolean


Answer: a) integer

Question 3: What is the output of the following PHP code snippet?

$var1 = 2;
$var2 = "2";
echo $var1 + $var2;
  • 22
  • 4
  • 0
  • 2

Answer: b) 4

Question 4: Which of the following is not a PHP data type?

  • boolean
  • integer
  • float
  • character

Answer: d) character

Question 5: What is the output of the following PHP code snippet?

$var1 = true;
$var2 = false;
echo gettype($var1) . " " . gettype($var2);
  • boolean boolean
  • integer integer
  • string string
  • boolean integer

Answer: a) boolean boolean

Question 6: Which of the following is not a PHP scalar data type?

  • boolean
  • float
  • array
  • string

Answer: c) array

Question 7: What is the output of the following PHP code snippet?

$var1 = 10;
$var2 = "10";
if ($var1 === $var2) {
  echo "Equal";
} else {
  echo "Not Equal";
}
  • Equal
  • Not Equal
  • 10
  • Error

Answer: b) Not Equal

Question 8: Which of the following data types is used to store a collection of key-value pairs in PHP?

  • integer
  • float
  • boolean
  • array

Answer: d) array

Question 9: What is the output of the following PHP code snippet?

$str = "123abc";
$num = (int) $str;
echo gettype($num) . " " . $num;
  • string 123abc
  • integer 123
  • string 123
  • integer 123abc

Answer: b) integer 123

Question 10: Which of the following data types is used to represent a null value in PHP?

  • boolean
  • integer
  • null
  • string

Answer: c) null

Question 11: What is the output of the following PHP code snippet?

$str1 = "hello";
$str2 = "world";
echo $str1 . " " . $str2;
  • hello world
  • helloworld
  • "hello" "world"
  • "helloworld"

Answer: a) hello world

Question 12: Which of the following data types is used to store a sequence of characters in PHP?

  • integer
  • boolean
  • string
  • array

Answer: c) string

Question 13: What is the output of the following PHP code snippet?

$var1 = "10";
$var2 = "20";
echo $var1 + $var2;
  • 30
  • 1020
  • 0
  • NaN

Answer: b) 1020

Question 14: Which of the following data types is used to represent a list of ordered items in PHP?

  • string
  • integer
  • array
  • null

Answer: c) array

Question 15: What is the output of the following PHP code snippet?

$var1 = true;
$var2 = "false";
if ($var1 && !$var2) {
  echo "True";
} else {
  echo "False";
}
  • True
  • False
  • Nothing is outputted
  • Error

Answer: a) True

Question 16: Which of the following is a PHP non-scalar data type?

  • string
  • float
  • boolean
  • object

Answer: d) object

Question 17: What is the output of the following PHP code snippet?

$arr = array("apple", "banana", "cherry");
echo count($arr);
  • apple, banana, cherry
  • 3
  • 6
  • Error

Answer: b) 3

Question 18: Which of the following data types is used to store a boolean value in PHP?

  • integer
  • float
  • boolean
  • string

Answer: c) boolean

Question 19: What is the output of the following PHP code snippet?

$x = 5;
echo ++$x;
  • 6
  • 5
  • 11
  • Error

Answer: a) 6

Question 20: Which of the following data types is used to store large numbers with decimals in PHP?

  • boolean
  • integer
  • string
  • float

Answer: d) float 

Question 21: Which of the following operators is used for concatenating two strings in PHP?

  • *
  • /
  • .

Answer: d) .

Question 22: What is the output of the following PHP code snippet?

$x = 10;
echo ++$x + $x++;
  • 20
  • 21
  • 22
  • 11

Answer: b) 21

Question 23: Which of the following data types is used to represent nothing in PHP?

  • boolean
  • string
  • integer
  • null

Answer: d) null

Question 24: What is the output of the following PHP code snippet?

$x = 10;
if ($x == "10") {
  echo "Equal";
} else {
  echo "Not equal";
}
  • Equal
  • Not equal
  • Nothing is outputted
  • Error

Answer: a) Equal

Question 25: Which of the following data types is used to store a single character in PHP?

  • integer
  • string
  • boolean
  • float

Answer: b) string

5/5 (1)