PHP - strval() 函式



定義和用法

strval() 函式獲取變數的字串值。

語法

string strval ( mixed $value )

引數

序號 引數 描述
1

被轉換為字串的變數。

可以是任何標量型別或實現 __toString() 方法的物件。不能對陣列或未實現 __toString() 方法的物件使用 strval()。

返回值

此函式返回的字串值。此函式不格式化返回值。

依賴

PHP 4 及以上版本

示例

以下示例演示了 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>";
  ?>

輸出

這將產生以下結果:

  string(14) "Tutorialspoint"
  string(2) "40"
  string(0) ""
  string(5) "Array"
  string(0) ""
廣告