How we can check data type of any variable in php ?

Last updated 1 year, 9 months ago | 231 views 75     5

PHP | Check data type in php | gettype() | var_dump()

By using gettype() function we can check the data type of a variable.

we can also use var_dump() function for the same.

 

gettype()

<?php

echo gettype(102).'<br>';
echo gettype(true).'<br>';
echo gettype(new stdclass());

?>

//output

integer
boolean
object 

var_dump()

<?php

$var_1=21;
$var_2=2.99;
$var_3="www.studyzone4u.com";

echo var_dump($var_1)."<br>";
echo var_dump($var_2)."<br>";
echo var_dump($var_3);

?>

//output
int(21)
float(2.99) 
string(19) "www.studyzone4u.com"