In this tutorials, I am going to give you the list of php data types. PHP data types are divided in about 8 categories. Here is the list..,
PHP data types :
- Strings
- Boolean
- Float
- Integer
- Array
- NULL
- Resource
PHP String :
String is a stream of characters. They may be expressed in single or double quotes.
<?php
$v1="<p>Strings are expressed within double quotes</p>";
$v2='<p>Or single quotes as in this here</p>';
echo "<center><h1>PHP Strings</h1></center>";
echo $v1;
echo $v2;
?>
Output :
PHP Integer :
These are digits that span across the number line without decimals. PHP allows inputs of any digits between -2,147,483,648 and 2,147,483,647.
Integers must:
- Have at least a digit
- Have no decimals
- Be positive or negative
- Be stated in decimal, hexadecimal, or octal formats
<?php
$a=90273;
var_dump($a);
?>
The var_dump()
function is used to display structured information (type and value) about one or more variables.
Output :
PHP Float :
This statement parses numbers with decimal points and those with exponents.
<?php
$b = 3.14159;
var_dump($b);
?>
Output:
float(3.14159)
PHP Boolean
It is a variable that is often represented as bool. It is used in two states, which are to show whether the situation or outcome is TRUE or FALSE. It is used in conditional testing.
PHP Array
Arrays are variables that are used to store one or more (many) values. In the following example, the var_dump reveals an array.
<?php
$variables = array("Arrays","Boolean","integers");
var_dump($variables);
?>
Output :
array(3) { [0]=> string(6) "Arrays" [1]=> string(7) "Boolean" [2]=> string(8) "integers" }
PHP Object
It is a data type that stores instructions on how to process data. PHP objects must me declared explicitly, first under a class, which is a structure containing methods and properties.
<?php
class phones {
function phones() {
$this->company = "Apple";
}
}
// create an object
$model = new phones();
// show object properties
echo $model->company;
?>
Output :
Apple
PHP Null :
This data type returns only one value, which is NULL. It is returned if no value is assigned.
Values that are instantiated without value assignment are automatically given the NULL value. This data type may also be used to empty variables.
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
PHP Resource
It is a resource type that stores references to functions and external resources.
Happy Learning 🙂