PHP settype

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PHP : settype() function

Description

The settype() function is used to set the type of a variable.

Version

(PHP 4 and above)

Syntax

settype(var_name, var_type)

Parameters

Name

Description

Required /
Optional

Type

var_name

The variable being converted.

Required

Mixed*

var_type

Type of the variable. Possible values are : boolean, integer, float, string, array, object, null.

Optional

String

*Mixed : Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value

TRUE on success or FALSE on failure.

Value Type : Boolean.

Example :

  1. $var1='98';  

  2. $var2='01';  

  3. settype($var1, "integer");  

  4. settype($var2, "integer");  

  5. echo ($var1.'
    ');  

  6. echo ($var2.'
    ');  

  7. echo ($var1+$var2.'
    ');  

  8. ?>  

Output :

98
1
99