PHP Data Types MCQs
PHP Data Types MCQs : This section focuses on "Data Types" 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. How many different data types are available in php?
A. 6
B. 7
C. 8
D. 9
View Answer
Ans : C
Explanation: PHP allows eight different data types.
2. How many compound data types are available in php?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : C
Explanation: The first five are called simple data types and the last three are compound data types.
3. Which one is not a data type in PHP?
A. Resources
B. Objects
C. Null
D. Void
View Answer
Ans : D
Explanation: The void is not a data type in PHP.
4. The range of integers must lie between ___________?
A. -2^15 to 2^15.
B. -2^16 to 2^16.
C. -2^31 to 2^31.
D. -2^32 to 2^32.
View Answer
Ans : C
Explanation: The range of integers must lie between -2^31 to 2^31.
5. How many value does Boolean data type hold?
A. 1
B. 2
C. 3
D. 4
View Answer
Ans : B
Explanation: Boolean: Hold only two values, either TRUE or FALSE.
6. Objects are defined as instances of user defined classes that can hold ____________?
A. values
B. functions
C. both values and functions
D. None of the above
View Answer
Ans : C
Explanation: Objects are defined as instances of user-defined classes that can hold both values and functions.
7. What will be the output of the following PHP code?
<?php
if(TRUE)
echo "This condition is TRUE";
if(FALSE)
echo "This condition is not TRUE";
?>
A. This condition is TRUE
B. This condition is not TRUE
C. No Output
D. Error
View Answer
Ans : A
Explanation: This condition is TRUE is the output of the following PHP code.
8. What will be the output of the following PHP code?
<?php
$lfc = NULL;
echo $lfc;
?>
A. 0
B. Null
C. No Output
D. Error
View Answer
Ans : C
Explanation: The output of the following PHP code is no output.
9. What will be the output of the following PHP code?
<?php
$x1 = 10.58;
$x2 = 21.18;
$sum = $x1 + $x2;
echo $sum;
?>
A. 31
B. 32
C. 31.00
D. 31.76
View Answer
Ans : D
Explanation: 31.76 is the output of the following code.
10. What will be the output of the following PHP code?
<?php
$intArray = array( 10, 20 , 30);
echo "First Element: $intArray[3]
";
?>
A. First Element: 10
B. First Element: 20
C. First Element: 30
D. First Element:
View Answer
Ans : D
Explanation: As the third index is not available in $intArray so, the output is First Element:
11. What is the data type of $TV in this Line 1?
<php
$tax=10.3;
$TV="10.3+$TV"; # Line 1
?>
A. Integer
B. String
C. Unknown
D. No Output
View Answer
Ans : B
Explanation: The string is the data type of $TV in this Line 1
12. What is the data type of $TV in the above code?
<php
$TV;
echo gettype($TV);
?>
A. Integer
B. String
C. Unknown
D. Null
View Answer
Ans : D
Explanation: NULL is the data type of $TV in the above code
13. What will be the output of the following code?
<php
define('t',10.3);
$tax=t;
echo "t+$tax";
?>
A. 20.6
B. 10.3+10.3
C. t+10.3
D. t+$tax
View Answer
Ans : C
Explanation: t+10.3 will be the output of the following code
14. What is the data type of $Cost?
<php
$tax="17.5"
$Fridge=Whirlpool;
settype($Fridge,"string");
$Cost=$tax+$Fridge;
echo gettype($Cost);
?>
A. String
B. Integer
C. Null
D. Float
View Answer
Ans : B
Explanation: The integer is the data type of $Cost.
15. What will be the output of the following code?
<php
PCmodel="DellInspirion3542";
settype($PCmodel,"integer");
echo $PCmodel;
?>
A. 0
B. 3542
C. DellInspirion3542
D. Error
View Answer
Ans : A
Explanation: 0 be the output of the following code
16. Select the true statements. Once a constant is defined:
A. The value cannot be changed, but the variable can be unset
B. Neither the value can be changed nor variable can be unset
C. The value can be changed, but it cannot be unset
D. The value can be changed and variable can be unset
View Answer
Ans : B
Explanation: Neither the value can be changed nor variable can be unset the true statements.
17. What is gettype() function do?
A. gettype() function returns the type of the variable
B. gettype() function is used to set type to variable
C. gettype() function is used to change type to variable
D. None of the above
View Answer
Ans : A
Explanation: gettype() function returns the type of the variable
18. Constants, like variables, can hold _________.
A. integer
B. string
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: Constants, like variables, can hold integer, double or string
19. Ord ( ) function is used convert a ______.
A. Integer type into a string
B. Integer type into an array
C. Float type into an array
D. Array type into a string
View Answer
Ans : A
Explanation: Ord() function is used to convert an Integer type into a string.
20. Which data type in PHP offers special variables that hold the references of resources that are external to PHP?
A. Array
B. Resources
C. object
D. string
View Answer
Ans : B
Explanation: Resources data type in PHP offers special variables that hold the references of resources that are external to PHP.
Also check :
Discussion