strval()

Description

This function returns the string value of an expression. The expression can be of any scalar type or any object that implements the __toString() method. Arrays and Resources…

Syntax


string strval( mixed $expr )

Parameters

$expr
Expression for which the string value should be returned. Only scalar expressions and objects for which the __toString() method has been implemented.

Return Value

string
The passed expression as a string.

Examples

1. Example heading

This example passes variables of various types to strval() and dumps the return type and value with var_dump().

<?php
$trueVal     = true;
$falseVal    = false;
$intVal      = 6;
$floatVal    = 3.14;
$stringVal   = "Hello";
$nullVal     = null;
 
var_dump( strval( $trueVal ));
var_dump( strval( $falseVal ));
var_dump( strval( $intVal ));
var_dump( strval( $floatVal ));
var_dump( strval( $stringVal ));
var_dump( strval( $nullVal ));
?>

In the output below, each of the return values from strval() returns a string representation of the passed variable. Boolean variables return a “1” for true values and a null string (“”) for false values. Integer and float variables return the string containing the value itself with no special formatting of the results. A string variable just returns the passed string value. A null variable returns a null string (“”).

string(1) "1"
string(0) ""
string(1) "6"
string(4) "3.14"
string(5) "Hello"
string(0) ""

2. Passing Arrays

Description of example….



3. Passing Resources

Description of example….



4. Passing Objects

Description of example….



See Also

References

www.php.net – strval()