PHP: settype() function
Description
The settype() function is used to set the type of a variable.
Version:
(PHP 4 and above)
Syntax:
settype(var_name, var_type)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
var_name | The variable being converted. | Required | Mixed* |
var_type | Type of the variable. Possible values are : boolean, integer, float, string, array, object, null. | Optional | String |
*Mixed: Mixed indicates that a parameter may accept multiple (but not necessarily all) types.
Return value:
TRUE on success or FALSE on failure.
Value Type: Boolean.
Example:
<?php
$var1='98';
$var2='01';
settype($var1, "integer");
settype($var2, "integer");
echo ($var1.'<br>');
echo ($var2.'<br>');
echo ($var1+$var2.'<br>');
?>
Output:
98 1 99
View the example in the browser
Practice here online :
See also
PHP: Tips of the Day
Returns true if the given string is a palindrome, false otherwise
Example:
<?php function tips_palindrome($string) { return strrev($string) === (string) $string; } print(tips_palindrome('malayalam')); print("\n"); print(tips_palindrome(151)); ?>
Output:
1 1
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- React - JavaScript Library
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework