Skip to content
Justice Tech School

Casting and Conversion

Cast with (int), (float), (string), (bool) and (array). intval and floatval convert too. Numeric strings convert, others become 0.

Example
var_dump((int)"42abc", (float)"3.5", (bool)"0", (string)12);
var_dump(intval("0x1A", 16));

Result

int(42)
float(3.5)
bool(false)
string(2) "12"
int(26)

Exercise

Cast to int.

()"5"

Quiz Test

What is (bool)"0"?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.