PHP strval() function

Description

Get the string value of a variable.

Syntax

PHP strval() function has the following syntax.

string strval ( mixed $var )

Parameter

  • var - The variable that is being converted to a string.

Return

The string value of var.

Example

Convert class to a string


<?php//from ww  w .ja  v a 2s  . c  om
class StrValTest
{
    public function __toString()
    {
        return __CLASS__;
    }
}

// Prints 'StrValTest'
echo strval(new StrValTest);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions