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 Comment More infoAdvertise with us Next Article PHP | setlocale() Function S sid4321 Follow Improve Article Tags : Web Technologies PHP PHP-basics Similar Reads PHP | setlocale() Function The setlocale() function is an inbuilt function in PHP which is used to set locale information. Locale setting means assigning your system a geographical location and then perform certain functions based on the locale of the place. Usually, programs dealing with the date and time of other places dea 3 min read PHP strval() Function The PHP strval() function converts a given variable to a string. It takes a scalar variable (like integers, floats, and booleans) and converts it to its string representation. For arrays, objects, and resources, it does not work and may produce unexpected results.Syntaxstrval( $variable ) Parameter: 3 min read PHP get_resource_type() Function The get_resource_type() function is an inbuilt function in PHP that is used for returning the type of resource. Syntax: get_resource_type(resource $resource) Parameters: This function accepts one parameter that described below: $resource: This parameter specifies the evaluated resource handle name.R 1 min read PHP gettype() Function The PHP gettype() function returns the type of a variable as a string. It identifies the variable's data type, such as string, integer, array, boolean, etc., allowing developers to check and handle different data types dynamically.Syntax:string gettype ( $var )Parameter: This function accepts a sing 2 min read PHP | Gmagick setimagetype() Function The Gmagick::setimagetype() function is an inbuilt function in PHP which is used to set the image type. Syntax: Gmagick Gmagick::setimagetype( int $imgType ) Parameters: This function accepts a single parameter $imgType which holds an integer value corresponding to one of the IMGTYPE constants. All 2 min read PHP | Imagick setImageType() Function The Imagick::setImageType() function is an inbuilt function in PHP which is used to set the image type.Syntax:Â Â bool Imagick::setImageType( int $image_type ) Parameters: This function accepts a single parameter $image_type which contains an integer value corresponding to one of IMGTYPE constants. W 1 min read Like