Data type in php

Whenever we define variable, php automatically sets correct data type of variable. If we want to know data type of variable, we can use built-in function gettype(). which returns data type in string form. Let's try an example for finding data type of variables.


$num=10; print gettype($num);// result is integer $amount=50.23; print gettype($amount);// result is double $flag=true; print gettype($flag);// result is boolean $name="Marry Jane"; print gettype($name);// result is string


But it doesn't mean that we cann't set data type.

In php we can set data type of varible by using buit-in function settype(). See as in example




gettype($var);//result is string


gettype($var);//result is integer

print $var // result 35