Cast Operator
Cast operators change the type of the variable to the desired type. Conversion between the current format and the target format may happen.
The available casts are:
(int),(integer): cast to integer(bool),(boolean): cast to boolean(float),(double): cast to float(string): cast to string(array): cast to array(object): cast to object, of typestdClass. There is no operator to convert to a specific class type.(void): complement operator to theNoDiscardattribute. It is not really a cast operator.(unset): cast to NULL, deprecated since PHP 7.2(real): cast to float.
<?php
$foo = 10; // $foo is an integer
$bar = (boolean) $foo; // $bar is a boolean
?>
See Also
- A detailed look into PHP type casting
- Mastering Data Type Conversion In Php Through Type Casting
- Conversions
- Mastering the (array) cast