settype Function in PHP

What is settype() in PHP?

Explanation

PHP settype function is used to set variable type to a specified variable. It returns the value of specified type on successful type assignment and 0 on failure.

Syntax:


settype(var_name, var_type)

var_name - Variable name
var_type - Variable type

Possible return values are:


 Integer
 Boolean
 String
 Double
 NULL
 Array
 Object

Example :


<?php
$val1 = "123Hscripts";
$val2 = 3;
$val3 = "Hscripts";
settype($val1, "integer");
settype($val2, "float");
settype($val3, "float");
echo $val1."<br />";
echo $val2."<br />";
echo $val3."<br />"; ?>

Result :

123
3
0

In the above example, the first input value "123Hscripts" is converted as an integer and the second value "3" is converted as float.

PHP Topics


Ask Questions

Ask Question