PHP settype() Function | Tutorial
Tutorial -- Learning is not just about technology, but also about dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
PHP Tutorial
PHP Tutorial PHP Introduction PHP Installation PHP Syntax PHP Variables PHP echo/print PHP EOF(heredoc) PHP Data Types PHP Type Comparison PHP Constants PHP String PHP Operators PHP If...Else PHP Switch PHP Arrays PHP Array Sorting PHP Superglobals PHP While Loop PHP For Loop PHP Functions PHP Magic Constants PHP Namespaces PHP OOP PHP Quiz
PHP Forms
PHP Forms PHP Form Validation PHP Form - Required Fields PHP Form - Validate Email and URL PHP Complete Form Example PHP $_GET Variable PHP $_POST Variable
PHP Advanced
PHP Multidimensional Arrays PHP date() Function PHP include and require PHP Files PHP File Upload PHP Cookie PHP Session PHP E-mail PHP Secure E-mail PHP Error Handling PHP Exception Handling PHP Filters PHP Advanced Filters PHP JSON
PHP 7 New Features
PHP Database
PHP MySQL Introduction PHP Connect to MySQL PHP MySQL Create Database PHP MySQL Create Table PHP MySQL Insert Data PHP MySQL Insert Multiple Data PHP MySQL Prepared Statements PHP MySQL Read Data PHP MySQL Where Clause PHP MySQL Order By PHP MySQL Update PHP MySQL Delete PHP Database ODBC
PHP XML
PHP XML Expat Parser PHP XML DOM PHP XML SimpleXML
PHP and AJAX
AJAX Introduction PHP β AJAX and PHP PHP Example AJAX and MySQL PHP Example AJAX and XML PHP Example AJAX Live Search PHP Example AJAX RSS Reader PHP Example AJAX Poll
PHP Reference
PHP Array PHP Calendar PHP cURL PHP Date PHP Directory PHP Error PHP Filesystem PHP Filter PHP FTP PHP HTTP PHP Libxml PHP Mail PHP Math PHP Misc PHP MySQLi PHP PDO PHP SimpleXML PHP String PHP XML PHP Zip PHP Timezones PHP Image Processing PHP RESTful PHP PCRE PHP Available Functions PHP Composer
PHP Regular Expressions (PCRE)
PHP Dependency Management Tool
PHP settype() Function
The settype() function is used to set the type of a variable.
PHP Version Requirement: PHP 4, PHP 5, PHP 7
Syntax
bool settype ( mixed &$var , string $type )
Parameter Description:
- $var: The variable to be converted.
- $type: The possible values for type are:
- "boolean" (or "bool", from PHP 4.2.0)
- "integer" (or "int", from PHP 4.2.0)
- "float" (only usable after PHP 4.2.0, the "double" used in older versions is now deprecated)
- "string"
- "array"
- "object"
- "null" (from PHP 4.2.0)
Return Value
Returns TRUE on success, FALSE on failure.
Example
Example
<?php
$foo = "5bar"; // string
$bar = true; // boolean
var_dump($foo);
var_dump($bar);
settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
var_dump($foo);
var_dump($bar);
?>
Output:
string(4) "5bar"
bool(true)
int(5)
string(1) "1"
YouTip