O'Reilly logo

PHP Quick Scripting Reference by Mikael Olsson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 19

image

Type Conversions

PHP will automatically convert a variable’s data type as necessary given the context in which it is used. For this reason explicit type conversions are seldom required. Nonetheless, the type of a variable or expression may be changed by performing an explicit type cast.

Explicit casts

An explicit cast is performed by placing the desired data type in parentheses before the variable or value that is to be evaluated. In the example below, the explicit cast forces the bool variable to be evaluated as an int.

$myBool = false;$myInt = (int)$myBool; // 0

One use for explicit casts can be seen when the bool variable is sent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required