Data Types

PHP Data Types

PHP data types are divided in two main categories: scalar and composite.

Scalar Data Types: Scalar types means that the value only can contains one value at a time. Next are scalar types:

  • Boolean: Boolean values are true or false, also 0 and empty string evaluates to false, and any numeric value different than zero or a string that is not empty evaluates to true.
  • Int: Is a signed numeric integer value, for example: 7, 34, 12345
  • Float: Float or real numbers has a floating point, for example 5.7, 11.8

    Numeric values can be represented in different ways:

  • Integers can use 3 notations:
    • Decimal: 7, -14, 123
    • Octal: 0666, 0100
    •  Hexadecimal: 0x3f, -0x123
  • Floating numbers can use 2 notations:
    • Decimal: 0.7, 14.23, -0.34
    •  Exponencial: 2E7, 1.2e2

  • String: We usually think strings are equivalent to text, but PHP strings are collections of binary data, in other words, strings can contains text, an image file even sound file.

Compound Data Types: Compound types store other data, PHP supports Arrays and Objects.

  • Arrays: An array is a collection of elements of heterogeneous type (numbers, Boolean values, strings, objects and even other arrays)
  • Objects: An object is a collection of data and code, they form the basis of Object-oriented Programming.

Other Data Types: There are another types of data that you can use in some situations:

  • Null: Means that a variable is empty (has no value).
  • Resource: Its use is for operations with files or another not native PHP resource.
0
Your rating: None

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [as], [as3], [css], [drupal5], [drupal6], [html], [java], [javascript], [mysql], [php], [xml].
  • You may quote other posts using [quote] tags.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.