O'Reilly logo

Webmaster in a Nutshell, Second Edition by Robert Eckstein, Stephen Spainhour

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Data Types

PHP provides three primitive data types: integers, floating-point numbers, and strings. In addition, there are two compound data types: arrays and objects.

Integers

Integers are whole numbers. The range of integers in PHP is equivalent to the range of the long data type in C. On 32-bit platforms, integer values can range from -2,147,483,648 to +2,147,483,647. PHP automatically converts larger values to floating-point numbers if you happen to overflow the range. An integer can be expressed in decimal (base-10), hexadecimal (base-16), or octal (base-8). For example:

$decimal=16; 
$hex=0x10;  
$octal=020;

Floating-Point Numbers

Floating-point numbers represent decimal values. The range of floating-point numbers in PHP is equivalent to the range of the double type in C. On most platforms a double can range from 1.7E-308 to 1.7E+308. A double may be expressed either as a regular number with a decimal point or in scientific notation. For example:

$var=0.017;  
$var=17.0E-3

Note that PHP also has a set of functions known as the binary calculator (BC) functions. These functions can manipulate arbitrary precision numbers. You should use these functions when dealing with very large numbers or numbers that require a high degree of precision,

Strings

A string is a sequence of characters. A string can be delimited by single quotes or double quotes:

"Hello, World!"

Double-quoted strings are subject to variable substitution and escape sequence handling, while single-quoted strings are not. For ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required