• PHP Video Tutorials

PHP - strval() Function



Definition and Usage

The function strval() gets string value of a variable.

Syntax

string strval ( mixed $value )

Parameters

Sr.No Parameter Description
1

value

The variable that is being converted to a string.

value may be any scalar type or an object that implements the __toString() method. You cannot use strval() on arrays or on objects that do not implement the __toString() method.

Return Values

This function returns string value of value. This function does not format the returned value.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of function strval():

  <?php
  $a = "Tutorialspoint";
  var_dump(strval($a)) ;
  echo "<br>";
  $b = 40;
  var_dump(strval($b));
  echo "<br>";
  $c = NULL;
  var_dump(strval($c));
  echo "<br>";
  $d = array("a", "b", "c");
  var_dump(strval($d)); //This will print only the type of value being converted i.e. 'Array'
  echo "<br>";
  $e = '';
  var_dump(strval($e));
  echo "<br>";
  ?>

Output

This will produce following result −

  string(14) "Tutorialspoint"
  string(2) "40"
  string(0) ""
  string(5) "Array"
  string(0) ""
Advertisements