Welcome back to php series tutorial. Last day we discuss about "Hardware and Software Requirements". Today we are going to discuss about php data types. If you miss previous series then have a look at previous tutorials.
PHP Data Types:

PHP has eight different types of values, or data types. The first five are basic: integers, floating-point numbers, strings, booleans, and null.
Two others are composed of the basic types, otherwise known as composite types. These include arrays,objects discussed in upcoming tutorials. Additionally, the resource type denotes a non-native type, such as an open file or a database connection.
Integers:
Integers are whole numbers. The range of integers in PHP is equivalent to the range of the so-called long data type of the C language. Typically, this means they range from –2,147,483,648 to +2,147,483,647 on a 32-bit architecture, but may vary depending on your platform.
PHP allows you to write integers in three ways: decimal, octal, and hexadecimal. Decimal digits are the ordinary, base-10 numbers we use in day-to-day life. You write decimal values as a sequence of digits, without leading zeros. The sequence may begin with a plus (+) or minus (-) sign to show whether the number is negative or positive. You may not include commas in integers.
Octal, or base-8 numbers, consist of a sequence of digits from 0 to 7, prefixed by a leading zero. Octal numbers are useful in some contexts, such as file permissions. You may have experienced setting the permissions on a UNIX file with an octal number like 0744.
Hexadecimal, or base-16 values, begin with 0x, followed by a sequence of digits (0 to 9) or letters ranging from A to F. The case of the letters does not matter.
Floating-Point Numbers:
Floating-point numbers represent numeric values with decimal digits, which are equivalent to the range of the double data type of the C language. Floating-point numbers are also called real numbers or doubles. The range and accuracy of real numbers varies from one platform to another.
Usually, this range is significantly greater than the range of integers. You can write a floating-point number in the ordinary way: a sequence of digits, a decimal point, and a sequence of digits. You may also write floating-point numbers in scientific notation, otherwise known as exponential notation. This form allows for the letter E followed by a power of 10. For example, you can write 3.2 billion as 3.2E9. The E may be uppercase or lowercase. The power of 10 must be an integer, of course.
Unlike integers, floating-point values have limited accuracy. Each floating-point number uses a block of memory, part of which holds the values of the digits and part of which holds the power of 10 applied to those digits. At times, a floating-point value may appear to gain or lose a very small amount of value due to the quirks of the floating-point number format. A detailed discussion is beyond the scope of this text.
However, knowing they perform this way, you should take care not to use them in situations where you need exact precision.
Strings:
Web applications usually move text around more often than they make complex mathematical calculations. Strings represent a sequence of characters of limited length and can contain any kind of data, including binary data. You can write a string value by surrounding it by single-quotes (') or double-quotes ("). Whichever you choose, the opening quote character must match the closing quote character.
PHP interprets characters inside single quotes as-is: Each character between quotes becomes one character in the string. If you need to include a single quote in the string, you may place a backslash (\) immediately before it. PHP understands the \' sequence stands for a single character and does not treat the single quote as the end of the string literal. Likewise, you may use two backslashes to represent a single backslash in the string value. Generally, these are called escape sequences.
Strings in double quotes may contain variables and additional escape sequences. PHP replaces references to variables with their values. Follwing table contains escape sequences recognized by PHP.
| code | Description |
| \" | Double quotes |
| \\ | Backslash character |
| \n | New line |
| \r | Carriage return |
| \t | Horizontal tab |
| \x00 - \xFF | Hex characters |
Booleans:
The boolean type, named after mathematician George Boole, contains only two values—true and false. The control statements discussed in Chapter 3 use boolean values to decide whether to execute blocks of code, and the comparison operators discussed later in this chapter resolve to boolean values.
You can write boolean values with the TRUE and FALSE constants. You can also allow PHP to convert a string, integer, or floating-point value to boolean. Follwing table describes how PHP converts values of other types to booleans.
| Data Type | Value | Boolean Value |
| Integer or Floating-Point | 0 | FALSE |
| Any other value | TRUE | |
| String | "" (empty string) | FALSE |
| Any other value | TRUE | |
| Array | Array with no elements | FALSE |
| Array with one or more elements | TRUE | |
| Object | Any instantiated object | TRUE |
| Null | NULL | FALSE |
Null:
Null is a special type that stands for the lack of value. It is typically used to initialize and reset variables or to check whether or not a variable is initialized. You can use the NULL constant to unset a variable.
Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!
Like our site? Be a member of Coolajax fan page to get daily posts updates!
Tags:
php data types, what is php data type, eight different types, integers type, floating-point numbers, strings,booleans, php, tutorials, code, script
Total Read: 505 Topics