As we showed you before, variables in PHP do not have to be defined as in some other programming languages. How are they are some instances where you want to force a variable into a particular type as oppose to having PHP assigned the data type for you. This is called variable casting. The following in an example of casting in PHP,
$myVar = 8;
$myVar = (string) $myVar ;
$myVar = (integer) $myVar;
gettype, settype
Gettype and settype, can be used to to do the variable castinig for you in PHP as well as get the current datatype of the variable. Gettype as the name implies get the variable type for the current variable
$myNum = 8;
echo gettype($myNum) ;
This will display the value “integer” as the type of the variable.
settype($myNum, “string”);
echo gettype ($myNum);
This displays the value “string”.


