PHP - Data Type Cast Full List

Introduction

Here's the full list of casts that you can use in PHP:

Function Description
(int) value or (integer) valueReturns value cast to an integer
(float) valueReturns 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) valueReturns 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:

FunctionDescription
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).

Related Topic