Home »
Aptitude Questions and Answers »
PHP Aptitude Questions and Answers
PHP Data Types Aptitude Questions and Answers
PHP Data Types Aptitude Questions and Answers: This section contains aptitude questions and answers on PHP Data Types.
By Nidhi Last updated : December 15, 2023
This section contains Aptitude Questions and Answers on PHP Data Types.
1) There are the following statements that are given below, which of them are correct about data types in PHP?
- In PHP, variables can store different type of data that is allowed according to PHP data-types.
- In PHP, there is no need to use special keywords to specify the data type of variable.
- In PHP, we use the 'int' keyword to declare an integer type variable.
- We use predefined classes to specify data-types in PHP.
Options:
- Only A
- Only B
- A and B
- C and D
Correct answer: 3
A and B
Statements A and B are correct about data-types in PHP.
2) There are the following data types that are given below, which of them are supported by PHP?
- String
- Array
- Object
- Resource
Options:
- A and B
- C and D
- A, B, and C
- A, B, C, and D
Correct answer: 4
A, B, C, and D
All given data-types are supported by PHP.
3) Which of the following is the correct range of integer variable in PHP?
- -32768 to 32767
- -2,147,483,648 to 2,147,483,647
- -128 to 127
- None of the above
Correct answer: 2
-2,147,483,648 to 2,147,483,647
In PHP we used 4-bytes integer then its range is from -2,147,483,648 to 2,147,483,647.
Learn: PHP Numbers
4) Which of following function is used to return data type of a variable and its value?
- get_type()
- var_type()
- var_dump()
- getType()
Correct answer: 3
var_dump()
The var_dump() function returns data-type of a variable and its value.
5) What is correct output of given code snippets in PHP?
<?php
$num = 256;
var_dump(num);
?>
- int(256)
- integer(256)
- string(3) "num"
- None of the above
Correct answer: 3
string(3) "num"
The above code will print a string(3) "num" on the webpage because we did not use the $ symbol with variable name in var_dump() function.
6) What is correct output of given code snippets in PHP?
<?php
$num = 256;
var_dump($num);
?>
- int(256)
- integer(256)
- string(3) "num"
- None of the above
Correct answer: 1
int(256)
The above code will print "int(256)" on the web page.
7) What is correct output of given code snippets in PHP?
<?php
$num = 256;
$num1 = var_dump($num);
echo "num1 is ".$num1;
?>
- int(256) num1 is int(256)
- int(256) num1 is
- Syntax error
- None of the above
Correct answer: 2
int(256) num1 is
The above code will print "int(256) num1 is" on the webpage.
8) What is correct output of given code snippets in PHP?
<?php
$num = "Hello";
var_dump($num);
?>
- string(hello)
- string("hello")
- string(5) "hello"
- None of the above
Correct answer: 3
string(5) "hello"
The above code will print [string(5) "hello"] on the web page.
9) What is correct output of given code snippets in PHP?
<?php
$num = 256;
var_dump($num);
$num = "Hello";
var_dump($num);
?>
- int(256)
- int(256) string(5) "Hello"
- int(256) string(3)
- syntax error
Correct answer: 2
int(256) string(5) "Hello"
The above code will print [int(256) string(5) "Hello"] on the web page.
10) What is correct output of given code snippets in PHP?
<?php
$num = true;
var_dump($num);
?>
- bool(true)
- boolean(true)
- bool(4) "true"
- boolean(4) "true"
Correct answer: 1
bool(true)
The above code will print "bool(true)" on the web page.
11) What is correct output of given code snippets in PHP?
<?php
$usrArray = array("ABC","PQR","XYZ");
var_dump($usrArray);
?>
- array(3) string
- array(3) { [0]=> string(3) "ABC" [1]=> string(3) "PQR" [2]=> string(3) "XYZ" }
- Syntax error
- None of the above
Correct answer: 2
array(3) { [0]=> string(3) "ABC" [1]=> string(3) "PQR" [2]=> string(3) "XYZ" }
Learn: PHP Arrays
12) What is correct output of given code snippets in PHP?
<?php
$usrArray = array("ABC",786,"XYZ");
var_dump($usrArray);
?>
- array(3) { [0]=> string(3) "ABC" [1]=> string(3) 786 [2]=> string(3) "XYZ" }
- array(3) { [0]=> string(3) "ABC" [1]=> int(786) [2]=> string(3) "XYZ" }
- Syntax error
- None of the above
Correct answer: 2
array(3) { [0]=> string(3) "ABC" [1]=> int(786) [2]=> string(3) "XYZ" }
13) In PHP, NULL is a data type?
- Yes
- No
Correct answer: 1
Yes
In PHP, NULL is also data-type which can have only one value null.
Learn: PHP NULL
14) What is correct output of given code snippets in PHP?
<?php
$x = null;
var_dump($x);
?>
- NULL
- NULL(4)
- NULL(null)
- None of the above
Correct answer: 1
NULL
The above code will print NULL on the webpage.
15) Can we create a user-defined class in the PHP script?
- Yes
- No
Correct answer: 1
Yes
Yes, we can create a user-defined class in the PHP script.
16) There are the following statements that are given below, which of them are correct about resource type in PHP?
- The resource type is used to contain the reference to the function.
- The resource type is used to store the reference of external resources.
- The resource type is used for the database call.
- None of the above
Options:
- A and B
- B and C
- A, B, and C
- D
Correct answer: 3
A, B, and C
Statements A, B, and C are correct about resource type in PHP.
17) What is the correct output of given code snippets in PHP?
<?php
class Sample
{
function Sample()
{
$Var1 = "India";
}
}
// create an object of Sample class
$obj = new Sample();
echo $obj->$Var1;
?>
- India
- Error
Correct answer: 2
Error
The above code will generate an error because $Var1 is not a member of the Sample class.
18) What is the correct output of given code snippets in PHP?
<?php
class Sample
{
function Sample()
{
$this->$Var1 = "India";
}
}
// create an object of Sample class
$obj = new Sample();
echo $obj->$Var1;
?>
- India
- Error
Correct answer: 1
India
The above code will print "India" on the web page.
19) What is the correct output of given code snippets in PHP?
<?php
class Sample
{
function Sample()
{
$this->$Var2 = "Australia";
$this->$Var1 = "India";
}
}
// create an object of Sample class
$obj = new Sample();
var_dump($obj);
?>
- object(Sample)#1 (1) { [""]=> string(5) "India" }
- object(Sample)#1 (2) { [""]=> string(5) "Australia" }
- Error
- None of the above
Correct answer: 1
object(Sample)#1 (1) { [""]=> string(5) "India" }