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?
  1. In PHP, variables can store different type of data that is allowed according to PHP data-types.
  2. In PHP, there is no need to use special keywords to specify the data type of variable.
  3. In PHP, we use the 'int' keyword to declare an integer type variable.
  4. We use predefined classes to specify data-types in PHP.

Options:

  1. Only A
  2. Only B
  3. A and B
  4. C and D

2) There are the following data types that are given below, which of them are supported by PHP?
  1. String
  2. Array
  3. Object
  4. Resource

Options:

  1. A and B
  2. C and D
  3. A, B, and C
  4. A, B, C, and D

3) Which of the following is the correct range of integer variable in PHP?
  1. -32768 to 32767
  2. -2,147,483,648 to 2,147,483,647
  3. -128 to 127
  4. None of the above

4) Which of following function is used to return data type of a variable and its value?
  1. get_type()
  2. var_type()
  3. var_dump()
  4. getType()

5) What is correct output of given code snippets in PHP?
<?php  
	$num = 256;
	var_dump(num);
?>
  1. int(256)
  2. integer(256)
  3. string(3) "num"
  4. None of the above

6) What is correct output of given code snippets in PHP?
<?php  
	$num = 256;
	var_dump($num);
?>
  1. int(256)
  2. integer(256)
  3. string(3) "num"
  4. None of the above

7) What is correct output of given code snippets in PHP?
<?php  
	$num = 256;
	$num1 = var_dump($num);
	echo "num1 is ".$num1;
?>
  1. int(256) num1 is int(256)
  2. int(256) num1 is
  3. Syntax error
  4. None of the above

8) What is correct output of given code snippets in PHP?
<?php  
	$num = "Hello";
	var_dump($num);
?>
  1. string(hello)
  2. string("hello")
  3. string(5) "hello"
  4. None of the above

9) What is correct output of given code snippets in PHP?
<?php  
	$num = 256;
	var_dump($num);

	$num = "Hello";
	var_dump($num);
?>
  1. int(256)
  2. int(256) string(5) "Hello"
  3. int(256) string(3)
  4. syntax error

10) What is correct output of given code snippets in PHP?
<?php  
	$num = true;
	var_dump($num);
?>
  1. bool(true)
  2. boolean(true)
  3. bool(4) "true"
  4. boolean(4) "true"

11) What is correct output of given code snippets in PHP?
<?php  
	$usrArray = array("ABC","PQR","XYZ");
	var_dump($usrArray);
?>  
  1. array(3) string
  2. array(3) { [0]=> string(3) "ABC" [1]=> string(3) "PQR" [2]=> string(3) "XYZ" }
  3. Syntax error
  4. None of the above

12) What is correct output of given code snippets in PHP?
<?php  
	$usrArray = array("ABC",786,"XYZ");
	var_dump($usrArray);
?>  
  1. array(3) { [0]=> string(3) "ABC" [1]=> string(3) 786 [2]=> string(3) "XYZ" }
  2. array(3) { [0]=> string(3) "ABC" [1]=> int(786) [2]=> string(3) "XYZ" }
  3. Syntax error
  4. None of the above

13) In PHP, NULL is a data type?
  1. Yes
  2. No

14) What is correct output of given code snippets in PHP?
<?php
	$x = null;
	var_dump($x);
?>
  1. NULL
  2. NULL(4)
  3. NULL(null)
  4. None of the above

15) Can we create a user-defined class in the PHP script?
  1. Yes
  2. No

16) There are the following statements that are given below, which of them are correct about resource type in PHP?
  1. The resource type is used to contain the reference to the function.
  2. The resource type is used to store the reference of external resources.
  3. The resource type is used for the database call.
  4. None of the above

Options:

  1. A and B
  2. B and C
  3. A, B, and C
  4. D

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;
?>
  1. India
  2. Error

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;
?>
  1. India
  2. Error

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);
?>
  1. object(Sample)#1 (1) { [""]=> string(5) "India" }
  2. object(Sample)#1 (2) { [""]=> string(5) "Australia" }
  3. Error
  4. None of the above

Learn PHP programming with our PHP tutorial.

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.