PHP data Types
The data type defines a set of values and set of operations on those
In PHP there are following data types
The data type which is used to store a whole number with no fractional part is called Integers Data type, (…,-3,-2,-1,0,1,2,3,… ) such as 54,320 etc. Integers can be specified in decimal (base 10), hexadecimal (base 16 – prefixed with 0x), octal (base 8 – prefixed with 0) notation, or binary (base 2) notation optionally preceded by a sign (- or +).
$ Var_Name = Int_Value;
$ marks = 97;
$x = 55;
echo $x.’ is an integer.’ ;
55 is an integer.
A string is a sequence or a combination of multiple characters. Like “Hello Smith”.A type of data used to store string values is known as String data type. It may include uppercase , lowercase, special symbols and space.
$var_Name = “String”;
$Var_Name = ‘String’;
$x = “Display using double quotation marks!”;
$y = ‘Display using single quotation marks!’;
echo $x. “<br>”;
Display using double quotation marks!
Display using single quotation marks!
PHP Float / Double
Float data type is used to store real values. Floating point number is a number in exponential form or with a decimal point.
$Var_Name = decimal_number;
$Var_Name = Exponential_int;
$a = 1.432;
$b = 1.4e3;
echo $a.’ is Floating-point number. <br>’;
echo $b. ‘ is an Exponential integer.’;
1.432 is Floating point number.
1400 is Exponential integer.
An Array is a type of data structure that allows to store multiple elements of similar data type in a single variable. The elements of that variable consists of different memory locations. These locations are adjacent in memory and are indicated with same name.
$Array_Name = array( Elements_of_Array );
Boolean is a data type that represents only two possible values (TRUE or FALSE). It is used
in control structure.
An Object is a PHP data type that allows storing data and information on, how to process that data. OBJECT is an instance of a class. An object consists on methods and properties to make a particular
type of data useful.
PHP Null is a special type of data that is used in PHP to represent empty variables. A Null type of variable has no value to assigned it.
$a = NULL;
$b = “Practicing Null Data type!”;
$b = NULL;
A resource is a special data type that stores references of functions and external resources to PHP.
The most common example of resource data type is database connection .
To learn about PHP Variables CLICK HERE.