diff --git a/guide/english/php/type-casting/index.md b/guide/english/php/type-casting/index.md new file mode 100644 index 0000000000..e098b36c8e --- /dev/null +++ b/guide/english/php/type-casting/index.md @@ -0,0 +1,60 @@ +--- +title: Type Casting +--- + +## Type Casting in PHP + +In PHP, variable types are not explicitly declared. Instead, a variables type is determined by what value is assigned to that variable. That is to say, if a string value is assigned to variable $var, $var becomes a string. If an integer value is then assigned to $var, $var becomes an integer. + +As you can imagine, this can cause some issues at times. For example, if I assign a variable the value "123", it is a string, but if I assign it 123, it will be an int. + +Sometimes we want to ensure that a variable is of a certain type, and that is where type casting comes in. It allows us to define the type of a variable to ensure we get the correct value from that variable. + +## Syntax + +To cast a variable to a specific type, simply write the type inside parenthesis in front of the variable. + + +``` + +(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
+ + +For more information, please see [PHP: Type Juggling](http://php.net/manual/en/language.types.type-juggling.php)