Приглашаем посетить
Паустовский (paustovskiy-lit.ru)

Section 5.1.  Types of Data

Previous
Table of Contents
Next

5.1. Types of Data

PHP has seven data types , and all but one hold a specific kind of information. The seven types are: string, integer, float, boolean, array, object, and resource. You'll be using them all at different times throughout this book, so it is worth remembering what they are.

Strings hold characters (literally: a string of characters) such as "a," "abc," "Jack and Jill went up the hill to fetch a pail of water," etc. Strings can be as short or as long as you wantthere's no limit to size. PHP considers strings to be case-sensitive (i.e., Foo and FOO are different), which means that some string functions have case-insensitive equivalents.

Integers hold whole numbers, either positive or negative, such as 1, -20, 55028932, etc. There is a maximum limit to the size of integersany numbers lower than -2147483647 and any numbers higher than 2147483647 are automatically converted to floats, which can hold a much larger range of values.

Floats hold fractional numbers as well as very large integer numbers, such as 4.2, 1.00000001, and 2147483647000.

Booleans hold either true or false. Behind the scenes, booleans are, in fact, just integersPHP considers the number 0 to be false, and everything else to be true.

Arrays are a special variable type in that they hold multiple values like a container, and can even hold arrays of arrays (known as multidimensional arrays).

Like arrays, objects are complex variables that have multiple values, but they can also have their own functions (often called methods) associated with them. We cover this in Chapter 8.

Resources are anything that is not PHP datathis might be picture data you have loaded from a file, the result of an SQL query, and so on. Internally, a resource variable holds a handle to the actual data, because it is created outside of PHP. This means you should free up your resources when you are finished with them.


Previous
Table of Contents
Next