PHP Data Types

PHP Data Types-

PHP Data Types, Variables can store data of different types, PHP supports 8 primitive data types that can be categorized further into 3 types:
PHP Data Types image

  1. Scalar Types
  2. Compound Types
  3. Special Types

PHP Data Types: Scalar Types
There are 4 scalar data types in PHP.

  1. string
  2. float
  3. integer
  4. boolean

PHP Data Types: Compound Types

There are 2 compound data types in PHP.

  1. object
  2. array

Special Types
There are 2 special data types in PHP.

  1. resource
  2. NULL

PHP String
a string is a sequence of characters, like “Wellcome Tutorial Scan” and can be used singly or double quotes

Example:-

Output:

PHP Integer

  • PHP integer must have at least one digit
  • The integer must not have a decimal point
  • it 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)

Example:-

Output:-

PHP Float

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

$x is a float. The PHP var_dump() function returns the data type and value:

Example:-

Output:-

PHP Boolean-
A Boolean represents always two possible conditions: TRUE or FALSE.

PHP Array

An array stores multiple values in one single variable.

In the following example, $watch is an array. The PHP var_dump() function returns the data type and value:

Example:-

Output:-

 

 

Resource
PHP.net