Data Types In PHP With Examples

Data Types In PHP With Examples

The values assigned to a PHP variable may be of different data types including simple Integer, Floating point number or Float, String, Booleans  and null types to more complex data types like arrays and objects.

PHP supports the following Eight data types:

  1. Integer is data type non-decimal number between -2,147,483,648 and 2,147,483,647. Whole numbers, without a decimal point, like 4195.

In the following example $ DTH is an integer. The PHP var_dump() function returns the data type and value.

  1. Strings – A string is a order of characters, like “Hello Digital Technology Hub!”.

  1. PHP Floating Point Numbers or Doubles – Floating point numbers (also known as “floats”, “doubles”, or “real numbers”) are decimal or fractional numbers, like 4.45156 or 78.22.

  1. PHP Booleans – Booleans are like a switch it has only two possible values either 1 (true) or 0 (false).

  1. PHP Array – An array stores multiple values in one single variable, for example a set of country or city names.

  1. PHP Object – An object is a data type which stores data and information on how to process that data. In PHP, an object must be explicitly declared. First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods:

  1. NULL − is a special type that only has one value: NULL.

  1. PHP Resources – A resource is a special variable, holding a reference to an external resource.


Thanks for reading my article aboutData Types In PHP With Examples”. If you like this article do me favor by sharing it with your friends.

Digital Technology Hub