Star Hoster
Photoshop Tutorials
Anonymous Web Surfing
Funny Jokes
Myspace Friends
Open Treasure Chest
Building in Paradise


July 13, 2008

Variable Type Casting In Php

Filed under: Advanced PHP Tutorials — phpdeveloper @ 9:34 am

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”.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.