Here some description goes.....

>

PHP supports the following types:


• integer
• floating-point numbers
• string
• array
• object


The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP
depending on the context in which that variable is used.
If you would like to force a variable to be converted to a certain type, you may either cast the variable or
use the settype function on it.
Note that a variable may behave in different manners in certain situations, depending on what type it is a
the time. For more information, see the section on Type Juggling.
Integers
Integers can be specified using any of the following syntaxes:


$a = 1234; # decimal number
$a = -123; # a negative number
$a = 0123; # octal number (equivalent to 83 decimal)
$a = 0x12; # hexadecimal number (equivalent to 18 decimal)


Floating point numbers
Floating point numbers ("doubles") can be specified using any of the following syntaxes:

$a = 1.234;
$a = 1.2e3;

Strings
Strings can be specified using one of two sets of delimiters.

If the string is enclosed in double-quotes ("), variables within the string will be expanded (subject to
some parsing limitations). As in C and Perl, the backslash ("\") character can be used in specifying
special characters:
Table 5-1. Escaped characters




sequence meaning
\n newline
\r carriage
\t horizontal tab
\\ backslash
\$ dollar sign
\" double-quote


You can escape any other character, but a warning will be issued at the highest warning level.
The second way to delimit a string uses the single-quote ("’") character, which does not do any variable expansion or backslash processing (except for "\\" and "\’" so you can insert backslashes and single-quotes in a singly-quoted string).
String conversion
When a string is evaluated as a numeric value, the resulting value and type are determined as follows.
The string will evaluate as a double if it contains any of the characters ’.’, ’e’, or ’E’. Otherwise, it will
evaluate as an integer.
The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an ’e’ or ’E’ followed by one or more digits.
When the first expression is a string, the type of the variable will depend on the second expression.

$foo = 1 + "10.5"; // $foo is double (11.5)
$foo = 1 + "-1.3e3"; // $foo is double (-1299)
$foo = 1 + "bob-1.3e3"; // $foo is integer (1)
$foo = 1 + "bob3"; // $foo is integer (1)
$foo = 1 + "10 Small Pigs"; // $foo is integer (11)
$foo = 1 + "10 Little Piggies"; // $foo is integer (11)
$foo = "10.0 pigs " + 1; // $foo is integer (11)
$foo = "10.0 pigs " + 1.0; // $foo is double (11)

 


For more information on this conversion, see the Unix manual page for strtod(3).

Leave a Reply