PHP Data Types

In this chapter you will learn:

  1. Data types in PHP
  2. PHP String
  3. PHP Integer
  4. PHP Float
  5. PHP Boolean
  6. PHP Array
  7. PHP Object
  8. PHP Resource

Data types in PHP

PHP has seven data types. The seven types are:

  • string,
  • integer,
  • float,
  • boolean,
  • array,
  • object, and
  • resource.

String

Strings hold characters such as "a," "abc," "www.java2s.com," etc. PHP strings are case-sensitive.

Integer

Integers hold whole numbers, either positive or negative, such as 1, -20, 12345,etc. The limit of integer is between -2147483647 and 2147483647. The integer numbers outside the range are automatically converted to floats.

Float

Floats hold fractional numbers as well as very large integer numbers, such as 4.2, 1.00000001, and 123123123123000.

Boolean

Booleans hold either true or false. Behind the scenes, booleans are integers.

Array

Arrays are a special variable type in that they hold multiple values like a container.

Object

Objects are complex variables that have multiple values, and they can have their own functions.

Resource

Resources might be picture data, or the result of an SQL query. We should free up resources after using them.

Next chapter...

What you will learn in the next chapter:

  1. What is boolean value in PHP
  2. What values are considered false
  3. Example - Use PHP boolean value
  4. Example - Convert integer to boolean
Home » PHP Tutorial » PHP Data Types
PHP Data Types
PHP Boolean
PHP Integer
PHP Float
PHP Data Type Cast
PHP Automatic Type Conversion
PHP Super globals
PHP References
PHP Constants