elibraryportal Logo

Data Types in PHP

Variables can store different types of data like...

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

PHP String

A string is a sequence of characters, in closed in single or double quotes, that is called PHP String.

Example :-

Output

Visit Solvegk.com
Visit Sarkarirest.com

PHP Integer

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 three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)

PHP var_dump() function returns the data type and value:

Example :-

Output

int(12345)

PHP Floating Point Numbers or Doubles

floating point number is also known as decimal point or a number in exponential form.

Example :-

Output

 float(10.365)

The PHP var_dump() function returns the data type and value:


PHP Boolean

  • A Boolean represents TRUE or FALSE.
  • Booleans are often used in conditional testing.

Example :-

Output

 bool(true)

PHP Array

An array stores multiple values in one single variable.

Example :-

Output

array(3) { [0]=> string(5) "Volvo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" } 

PHP Object

An object is a data type which stores data and information . we use the class keyword. A class can contain properties and methods:

Example :-

Output

 VMW

PHP NULL

NULL value is used to empty variables in PHP.

Example :-

Output

 NULL

PHP Resources

PHP Resources means path or location that means related to database connections..

Example :-

Output


Next Topic