PHP Data Types

PHP supports the following eight data types:

  • boolean
  • integer
  • float
  • string
  • array
  • object
  • resource
  • null

Boolean

PHP boolean data type is anyone of true or false. Both true and false data types are case insensitive. You can learn more about this in PHP control structure.

Example

Integer

An integer is a number and should not contain any alphabet, comma, or blanks. The range of integer can be -2,147,483,648 to + 2,147,483,647. Integer can be specified in the following three formats: decimal (10 base), hexadecimal (16 base), binary (2 base). It may be positive or negative within the range.

Example

Floating-Point Numbers

PHP float is a number which should contain at least one decimal point or represented by exponential form.

Example

Strings

PHP string is any character represented within single (‘) or double (“) quotes.

Example

If a string is defined within single quote and you want same single quote to be specified within the text, then you should escape it with backslash (\)

Arrays

PHP array is a compound data type which contains one or more values and each value associated with the key.

Example

Objects

PHP object is a compound data type which contain both data and methods. To create a object you have to instantiate a class using “new” keyword.

Example

Resources

PHP resource is a special variable. It is the reference of an external resources. In the database connectivity and handling of file processing, the resource variable exists.

NULL

PHP null is a special data type which represent a variable having empty or no value. It is case insensitive.

If you have unset the variable then it will be considered as a variable with null value.

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *