This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Casting

Cast to String

string(1) "5"
string(4) "5.34"
string(5) "hello"
string(1) "1"
string(0) ""

Note that when casting a Boolean into string it gets the value "1", and when casting NULL into string it is converted into an empty string "".

<?php
// data types to be cast to strings
$a = 5;       // Integer
$b = 5.34;    // Float
$c = "hello"; // String
$d = true;    // Boolean
$e = NULL;    // NULL

// Casting to string
$a = (string) $a;
$b = (string) $b;
$c = (string) $c;
$d = (string) $d;
$e = (string) $e;

// To verify the type of any object in PHP, use the var_dump() function:
var_dump($a);
var_dump($b);
var_dump($c);
var_dump($d);
var_dump($e);
?>