PHP | settype() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The settype() function is a built-in function in PHP. The settype() function is used to the set the type of a variable. It is used to set type or modify type of an existing variable. Syntax: boolean settype($variable_name, $type) Parameters: The settype() function accepts two parameters as shown in above syntax and are described below. $variable_name: This parameter specifies the name of variable whose type we want to modify. This parameter can be of any type that is, it can be of integer type or a string type etc. $type: This parameter specifies the type of variable that is needed. Possible values of this parameter are: boolean, integer, float, string, array, object, null. Return value: This function returns a boolean type value. It returns TRUE in case of success and FALSE in case of failure. Below programs illustrate the settype() function in PHP: Program 1: PHP <?php // PHP program to illustrate settype() function $var1 = "123xyz"; $var2 = 3; $r = true; settype($var1, "integer"); settype($var2, "float"); settype($r, "string"); echo $var1."\n"; echo $var2."\n"; echo $r."\n"; ?> Output: 123 3 1 Program 2: PHP <?php // PHP program to illustrate settype() function $var1 = "a12b"; $var2 = 3.566; $r = true; settype($var1, "integer"); settype($var2, "integer"); settype($r, "string"); echo $var1."\n"; echo $var2."\n"; echo $r."\n"; ?> Output: 0 3 1 Reference: https://www.php.net/manual/en/function.settype.php Create Quiz Comment S sid4321 Follow 0 Improve S sid4321 Follow 0 Improve Article Tags : Web Technologies PHP PHP-basics Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like