PHP supports the following data types:-

  • String
  • Integer
  • Float
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

String:-
A string is a string of characters and that could used in single or double quotes:-
Example:-
<?php
$x = “Hello India!”;
$y = ‘Hello India!’;

echo $x;
echo “<br>”;
echo $y;
?>
Integer:-
An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. An integer must have at least one digit and it could be specified in three formats: decimal (10-based), hexadecimal (16-based) or octal (8-based).
Example:-
<?php
$x = 6995;
var_dump($x);
?>
Float:-
A float is a number with a decimal point or a number in exponential form.
Example:-
<?php
$x = 11.345;
var_dump($x);
?>
Boolean:-
A Boolean symbolize two possible states: TRUE or FALSE.

$x = true;
$y = false;
Array:-
An array stores multiple values in one variable.
Example:-
<?php
$ar = array(“india”,”japan”,”china”);
var_dump($ar);
?>
NULL Value:-
Null is a special data type which could have only one value that has no value assigned to it.
Example:-
<?php
$x = “Hello India!”;
$x = null;
var_dump($x);
?>

Categories: PHP

0 thoughts on “PHP Data Types”

Leave a Reply