PHP settype() Function

PHP strval() Function
PHP serialize() Function

In this article, you will learn how to convert a variable of one type into another type. The settype() function in PHP converts a variable to a specific type.

what is the syntax of the SETTYPE() function in php?

settype(variable, type);
ParameterDescription
variableRequired. Specifies the variable to convert
typeRequired. Specifies the type to convert variable to. The possible types are: boolean, bool, integer, int, float, double, string, array, object, null 
PHP SETTYPE() method

examples of the SETTYPE() function

Example 1. In this example, we convert variables to specific types.

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

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

$c = true; // boolean
settype($c, "integer"); // $c is now integer (1)
?>
PHP strval() Function
PHP serialize() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top