Here's the full list of casts that you can use in PHP:
Function | Description |
---|---|
(int) value or (integer) value | Returns value cast to an integer |
(float) value | Returns value cast to a float |
(string) value | Returns value cast to a string |
(bool) value or (boolean) value | Returns value cast to a Boolean |
(array) value | Returns value cast to an array |
(object) value | Returns value cast to an object |
You can cast a value to an integer, floating-point, or string value using three PHP functions:
Function | Description |
---|---|
intval( value ) | Returns value cast to an integer |
floatval( value ) | Returns value cast to a float |
strval( value ) | Returns value cast to a string |
intval() can convert from a non-base-10 integer to a base-10 integer.
To use this feature, pass intval() a string representation of the non-base-10 integer, followed by the base of the integer.
For example, intval("11",5) returns a value of 6 (the base-5 number 11 converted to a decimal number).