Changing the TYPE of a Variable with settype()

Chapter 5 #93 - Martha's CIS 52

ASSIGNMENT/EXPLANATION

This exercise creates a variable called "undecided", changes the value of it with settype(), and then tests the type of the variable.
An answer of "1" means it's true (it is a variable of that type); no answer means it is false (it is not a variable of that type).

NOTICE: Changing the type of an integer to a double deletes any information to the right of the decimal point.
Changing the type to "boolean" actually changes the value too!


Exercise

The variable 'undecided' has been declared to be 3.14.
Is 3.14 a double? 1
The type of variable 'undecided' has been changed now to 'string'.
Is 3.14 a string? 1
The type of variable 'undecided' has been changed now to 'integer'.
Is 3 an integer? 1
The type of variable 'undecided' has been changed now to 'double'.
Is 3 a double? 1
The type of variable 'undecided' has been changed now to 'boolean'.
Is 1 a boolean? 1

CODE

$undecided = 3.14;
echo "The variable 'undecided' has been declared to be 3.14."."<br />";
echo "Is ".$undecided." a double? ".is_double($undecided)."<br />"; // double
settype($undecided, 'string');
echo "The type of variable 'undecided' has been changed now to 'string'.";
echo "<br />";
echo "Is ".$undecided." a string? ".is_string($undecided)."<br />"; // string
settype($undecided, 'integer');
echo "The type of variable 'undecided' has been changed now to 'integer'.";
echo "<br />";
echo "Is ".$undecided." an integer? ".is_integer($undecided)."<br />"; // integer
settype($undecided, 'double');
echo "The type of variable 'undecided' has been changed now to 'double'.";
echo "<br />";
echo "Is ".$undecided." a double? ".is_double($undecided)."<br />"; // double
settype($undecided, 'bool');
echo "The type of variable 'undecided' has been changed now to 'boolean'.";
echo "<br />";
echo "Is ".$undecided." a boolean? ".is_bool($undecided)."<br />"; // boolean