Introduction
In this article I explain the settype() and gettype() functions in PHP. The gettype() function gets the type of variable; gettype() is a function that display a data type. The settype function sets the type of variable; the settype() function changes the data type.
Syntax
Parameter |
|
Var name |
Pass the variable name |
Return Value
Boolean, Integer, Double, String, Array, Object, Resource, NULL
Example1
<?php
$a=100;
echo gettype($a);
?>
Output
With Condition
In this example I am using "if" and "else" conditions.
Example2
<?php
$a=5;
if(is_int($a))
echo 'integer';
else
echo 'not integer';
?>
Output
Next, I will explain the settype() function in PHP. Such as:
Syntax
Example
<?php
$a=5.2;
echo gettype($a);
echo "<br>";
settype($a,"int");
echo gettype($a);
?>
Output