Data types define the type of data that a variable can hold. PHP provides the following built-in data types:
What is String datatype is PHP:
A sequence of characters, such as letters, numbers, and symbols, enclosed in single or double quotes.
<?php
$str = "Hello world!";
echo $str;
?>
Integer datatype in PHP:
A whole number (positive, negative, or zero) without a decimal point. An integer number typically ranging between -2,147,483,648 and 2,147,483,647.
<?php
$x = 55;
var_dump($x);
?>
Float datatype in PHP:
A number with a decimal point or a fractional component.
<?php
$x = 82.55;
var_dump($x);
?>
Boolean datatype in PHP:
A value that can be either true or false.
<?php
if (TRUE)
echo "This condition is TRUE.";
if (FALSE)
echo "This condition is FALSE.";
?>
Array Array datatype in PHP:
A collection of elements, each identified by a key, which can hold values of different data types.
<?php
$x =array("Mohan", "Ajit", "Vikash");
var_dump($x);
?>
NULL datatype in PHP:
Its represents the absence of a value.
<?php
$x =null;
?>
What is Object data type in PHP:
An instance of a class, which is a blueprint that defines the properties and methods of an object.
<?php
class car {
function model() {
$model_name = "BMW";
echo "car Model: " .$model_name;
}
}
$obj = new car();
$obj -> model();
?>
Output:
car Model: BMW