How many Data Types in PHP?

Data Types in PHP

The values assigned to a PHP variable may be of different data types including simple string and numeric types to more complex data types like arrays and objects. These data types are used to construct variables. In PHP, there are mainly eight data types are exists:

  1. Integers: They are whole numbers, without a decimal point, like 12345. It is the simplest data type in PHP. they correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions.
  2. Doubles: It prints with the minimum number of decimal places which needed. They like 3.14159.
  3. Boolean: It has only two possible values, either true or false. PHP provides a couple of constants especially for use as Boolean: TRUE and FALSE.
  4. NULL: It is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this:
    $my_var = NULL;
  5. Strings: It is a sequences of characters, enclosed in single or double quotes.
  6. Arrays: 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.
  7. Objects: An object is an instance of a class and is used to access methods and properties. Objects are explicitly declared and created from the new keyword.
  8. Resources: A resource is a special variable that holds a reference to an external resource.