Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

strval

Converts a value to a string.

Syntax

strval(mixed $value): string

Parameters

ParameterTypeDescription
$valuemixedA number, a boolean or an object with a `__toString()` method.

Return value

stringThe string form of the value.

Examples

A number and booleans:

<?php
 
var_dump(strval(42));
var_dump(strval(true));
var_dump(strval(false));

Output:

string(2) "42"
string(1) "1"
string(0) ""

Notes

true becomes '1', while false and null become an empty string. The (string) $value cast does the same.

See also

  • intval — Converts a value to an integer.
  • floatval — Converts a value to a float.
  • sprintf — Returns a string built from a format template.

In the tutorial

  • Data types — The main PHP data types — strings, numbers, booleans, arrays and null.

Thanks for reading!

Donate to the site — we work hard for you.