Current Location: Home> Function Categories> settype

settype

Set the type of variable
Name:settype
Category:Variable processing
Programming Language:php
One-line Description:Convert variables to specific types.

Definition and usage

settype() function converts a variable to a specific type.

Example

Convert variables to specific types:

 <?php
$a = "32" ; // string
settype ( $a , "integer" ) ; // $a is now an integer

$b = 32 ; // integer
settype ( $b , "string" ) ; // $b is now a string

$c = true ; // boolean
settype ( $c , "integer" ) ; // $c is now an integer (1)
?>

Try it yourself

grammar

 settype ( variable , type ) ;
parameter describe
variable Required. Specifies the variable to convert.
type

Required. Specifies the type to convert the variable to. Possible types are:

  • boolean
  • bool
  • integer
  • int
  • float
  • double
  • string
  • array
  • object
  • null
Similar Functions