Data Types in PHP

The values assigned to a PHP variable may be different data types integer, float, string, boolean, array, object, resourse and NULL.

  • PHP Integers: Integers are whole numbers, without a decimal point. Integers can be specified in decimal (base 10), hexadecimal (base 16 - prefixed with 0x) notation, optionally preceded by a sign (- or +).
  • PHP Strings:Strings are sequences of characters, where each character occupies one byte.A string can hold letters, numbers, and special characters. The simplest way to specify a string is to enclose it in single quotes (e.g. 'Hello world!'), however you can also use double quotes ("Hello world!").
  • PHP Booleans: Booleans are like a switch it has only two possible values either 1 (true) or 0 (false).
  • PHP Arrays: An array in PHP is actually an ordered map that maps values to keys. An array is a variable that can hold more than one value at a time. It is useful to aggregate a series of related items together, for example a set of country or city names
  • PHP Objects: An object is a data type that not only stores data but also information, how to process that data. An object is a specific instance of a class which serve as templates for objects. Objects are created based on this template via new keyword.
    Every object has properties and methods corresponding to those of its parent class. Every object instance is completely independent, with its own properties and methods, and can thus be manipulated independently of other objects of the same class.
  • PHP NULL: The special NULL value represents empty variables in PHP. A variable of type NULL is a variable without any data. NULL is the only possible value of type null.
    When a variable is created without value in PHP like ; it is automatically assigned a value null. Many PHP developers mistakenly considered both = NULL; and = ""; are same, but this is not true. Both variables are different - has null value while indicates no value assigned to it.
  • PHP Resources: A resource is special variable, holding a reference to external resource.
    Resource variables typically hold special handlers to opened files and database connections.