Data types in a programming language indicate what kinds of values are allowed to be used and processed. Data type is also a way to understand the binary level representation of those values in computer memory.  PHP data types are not a big concern to the PHP programmers since PHP is loosely typed language. It does not force a programmer to declare the variable before using it. This feature of PHP makes coding in PHP simple and flexible.

PHP Data Handling Advantages

There are three benefits that you will appreciate when working in PHP.

  • While working in PHP, you don’t have to declare variables. As soon you assign a value to a variable PHP data type is assigned by the value on the right hand side of assignment statement

$mySal= 50000;

$mySal is assigned integer data type with this assignment statement. If you write the next statement a string will be assigned to $mySal.

$mySal=’35000’;

  • If you are mixing up different PHP data types in one expression, you don’t have to worry about type casting or explicit data conversion. PHP handles it excellently by implicit data type conversion, of course into the higher data type in the expression.

$totAmt= 60+4.567;

In this expression 60 is first converted to floating point number and then added to second operand in sum expression. The result in floating point is assigned to $totAmt

PHP Data Types

 Integer

Integer data type refers to numbers without a decimal part. These are whole numbers with or without sign to represent positive and negative integers. Integer values in PHP range from –(231-1) to (231-1).

Floating Point

Floating Point or Doubles data type refers to numbers with decimal part. These are numbers with or without sign to represent positive and negative integers. You can write floating point numbers as fractions (97.5) or in exponential form (9.75E+1).

Boolean

In conditional statements or looping constructs we often need to check the truth value of condition(s). PHP data types include Boolean type for such needs. Booleans store true (1) or false (0) values.

NULL

Null means nothing, neither zero nor an empty string. Null means that a variable assigned  null is blank or lacks any value. If a variable is assigned NULL and passed as argument to IsSet() function, it returns Boolean false.

String

String is a collection of characters enclosed either in single quotation marks or double quotation marks. Single quote string is not interpolated in variables are embedded in it. Double quote string is not interpolated for variables and escape sequence embedded in it. A string length can be maximum 2GB.