Everything PHP: Types

Published on Apr 1, 2009   //  Development
Off

Everything PHP

Throughout this series, we have made references to which types a certain function uses. However, today we’re going to define the types of data we can use within PHP. This will help you learn which parts of PHP are capable of handling which types of data.

Boolean – The simplest type in PHP. A boolean type specifies whether something is true or false. As such, the only possible values are true and false (these are case-insensitive).

Integer – A whole number. The integer type can be specified in either decimal, hexadecimal or octal. Can be negative or positive.

Float – Floating point numbers (commonly know as double in other languages). This type is for numbers with decimal points, exponents or number beyond the bounds of an integer.

String – Any combination of characters (there 256 possible characters). Enclosed in either single- or double-quotes.

Array – An ordered map. See our article on arrays for more details. Can either be referenced using a variable, or by writing the array directly there.

Object – Has to do with functions nested in classes. Part of Object Oriented Programming, which we will be covering later in the series.

NULL – A type which has no value. The only possible value is NULL. Making a variable null will remove it’s value.

Variable – While it’s technically not a type, it’s still worth mentioning, as it can be used almost anywhere any other type can be used.

There you have it, PHP’s main accepted types. While this may not have been a very exciting article, knowing the difference between these types is crucial to understanding PHP’s documentation and actually putting it to use.

Page 11 of 11« First...7891011