Which is data type in php answer?

PHP Data Types

Variables can store data of different types, and different data types can do different things.

PHP supports the following data types:

  • String
  • Integer
  • Float [floating point numbers - also called double]
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

PHP String

A string is a sequence of characters, like "Hello world!".

A string can be any text inside quotes. You can use single or double quotes:

Example

Try it Yourself »

PHP Integer

An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

Rules for integers:

  • An integer must have at least one digit
  • An integer must not have a decimal point
  • An integer can be either positive or negative
  • Integers can be specified in: decimal [base 10], hexadecimal [base 16], octal [base 8], or binary [base 2] notation

In the following example $x is an integer. The PHP var_dump[] function returns the data type and value:

PHP Float

A float [floating point number] is a number with a decimal point or a number in exponential form.

In the following example $x is a float. The PHP var_dump[] function returns the data type and value:

PHP Boolean

A Boolean represents two possible states: TRUE or FALSE.

Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial.

PHP Array

An array stores multiple values in one single variable.

In the following example $cars is an array. The PHP var_dump[] function returns the data type and value:

Example

Try it Yourself »

You will learn a lot more about arrays in later chapters of this tutorial.

PHP Object

Classes and objects are the two main aspects of object-oriented programming.

A class is a template for objects, and an object is an instance of a class.

When the individual objects are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.

Let's assume we have a class named Car. A Car can have properties like model, color, etc. We can define variables like $model, $color, and so on, to hold the values of these properties.

When the individual objects [Volvo, BMW, Toyota, etc.] are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties.

If you create a __construct[] function, PHP will automatically call this function when you create an object from a class.

Example

Try it Yourself »

PHP NULL Value

Null is a special data type which can have only one value: NULL.

A variable of data type NULL is a variable that has no value assigned to it.

Tip: If a variable is created without a value, it is automatically assigned a value of NULL.

Variables can also be emptied by setting the value to NULL:

PHP Resource

The special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP.

A common example of using the resource data type is a database call.

We will not talk about the resource type here, since it is an advanced topic.



Home » Aptitude Questions and Answers » PHP Aptitude Questions and Answers

PHP Data Types Aptitude Questions and Answers: This section contains aptitude questions and answers on PHP Data Types.
Submitted by Nidhi, on May 22, 2020

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?


  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?


  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?


  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?


  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?


  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?


  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?

  
  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



13] In PHP, NULL is a data type?

  1. Yes
  2. No


14] What is correct output of given code snippets in PHP?


  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?


  1. India
  2. Error


18] What is the correct output of given code snippets in PHP?


  1. India
  2. Error


19] What is the correct output of given code snippets in PHP?


  1. object[Sample]#1 [1] { [""]=> string[5] "India" }
  2. object[Sample]#1 [2] { [""]=> string[5] "Australia" }
  3. Error
  4. None of the above



Which is data type in PHP?

PHP supports the following data types:.
String..
Integer..
Float [floating point numbers - also called double].
Boolean..
Array..
Object..
Resource..

What is data type answer?

A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.

Which one is data type?

A data type tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support basic data types of integer numbers [of varying sizes], floating-point numbers [which approximate real numbers], characters and Booleans.

How many data type are there in PHP?

PHP supports 8 primitive data types that can be categorized further in 3 types: Scalar Types [predefined] Compound Types [user-defined] Special Types.

Chủ Đề