Since PHP has loose data typing, changing variable’s data type is not commonly used because PHP will automatically cast variable types. But in some cases we need to change the variable data type upon processing the variable’s stored data.

There are two ways of changing data types in PHP

1. Using settype() PHP function
2. Type Casting

Using settype() PHP function

settype() will set the type of a variable.

Settype() accept two parameters

Syntax: settype($value, 'type');

Possibles values of type are:

“boolean” (or, since PHP 4.2.0, “bool”)
“integer” (or, since PHP 4.2.0, “int”)
“float” (only possible since PHP 4.2.0, for older versions use the deprecated variant “double”)
“string”
“array”
“object”
“null” (since PHP 4.2.0)

Example


<?php
$var = '35 days';
settype($var, "integer");

echo $var; // print 35
?>

Type Casting

Type casting in PHP works much as it does in C: the name of the desired type is written in parentheses before the variable which is to be cast.

Syntax: (type) $var;

The casts allowed are:

(int), (integer) – cast to integer
(bool), (boolean) – cast to boolean
(float), (double), (real) – cast to float
(string) – cast to string
(array) – cast to array
(object) – cast to object
(unset) – cast to NULL (PHP 5)
Example


<?php
$var = '35 days';
$var = (integer) $var; 

echo $var; // print 35
?>

How to take Cialis it seems to me that would already be time to cease to discuss this question. As I already answered it not once. Have it in a look. You shouldn’t worry! All deer go south when they are called by homesickness. Are turned and lie on snow till some hours.