PHP strval() function

In this chapter you will learn:

  1. Description for PHP strval() function
  2. Syntax for PHP strval() function
  3. Parameter for PHP strval() function
  4. Return value for PHP strval() function
  5. Example - Convert class to a string

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// ja v  a  2s .com
class StrValTest
{
    public function __toString()
    {
        return __CLASS__;
    }
}

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

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP checkdate() Function
  2. Syntax for PHP checkdate() Function
  3. Parameter for PHP checkdate() Function
  4. Return value from PHP checkdate() Function
  5. Example - validate a Gregorian date
Home » PHP Tutorial » PHP Data Type Functions
PHP boolval() function
PHP floatval() function
PHP gettype() function
PHP intval() function
PHP is_array(value) function
PHP is_bool() function
PHP is_float() function
PHP is_int() function
PHP is_null() function
PHP is_numeric() function
PHP is_object() function
PHP is_resource() function
PHP is_string() function
PHP isset() function
PHP settype() function
PHP strval() function