How to check datatype of variable in PHP

We will share with you how to check datatype of variable in PHP.

The gettype() function returns the type of a variable.

Example:

<!DOCTYPE html>
<html>
<body>
<?php
$num = 30;
echo gettype($num) . "<br>";

$dou = 13.2;
echo gettype($dou) . "<br>";

$str = "Hello";
echo gettype($str) . "<br>";

$arr = array();
echo gettype($arr) . "<br>";

$a = NULL;
echo gettype($a) . "<br>";

$bool = false;
echo gettype($bool) . "<br>";
?>
</body>
</html>

Output:

integer
double
string
array
NULL
boolean

You can run and check it.

I hope it will help you.

Tags: