May 2016
Intermediate to advanced
155 pages
2h 15m
English
© Mikael Olsson 2016
Mikael Olsson, PHP 7 Quick Scripting Reference, 10.1007/978-1-4842-1922-5_19
Mikael Olsson1
(1)Hammarland, Finland
PHP automatically converts 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.
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 following example, 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 ...
Read now
Unlock full access