← CodePrimer
PHP Beginner Basics

PHP type casting

How do I cast a value to another type?

(int) (string) (bool) casts.

Sample
<?php
$value = '42';
$asInt = (int) $value;
$asBool = (bool) $asInt;
$asString = (string) $asInt;

Notes

Loose typing still benefits from explicit casts at boundaries.

Keywords: cast · type · int · string · bool

Related

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share