strval()函数是PHP中的内置函数, 用于将任何标量值(字符串, 整数或双精度)转换为字符串。咱们不能在数组或对象上应用strval(), 如果利用了该函数, 则此函数仅返回要转换的值的类型名称。

语法:

strval( $variable )

参数:此函数承受单个参数$变量。此参数示意咱们要转换为字符串的值

返回值:此函数返回一个字符串。该字符串是通过类型转换作为参数传递给它的变量的值生成的。

上面的程序阐明了strval()函数。

程序1:

<?php  $var_name = 32.360;  // prints the value of above variable // as a stringecho strval ( $var_name );  ?>

输入如下:

32.36

程序2:

<?php  class lsbin{     public function __toString()     {            // returns the class name          return __CLASS__ ;     }}  // prints the name of above class as// a stringecho strval ( new lsbin);  ?>

输入如下:

lsbin

程序3:

<?php// Program to illustrate the strval() function// when an array is passed as parameter  // Input array$arr = array (1, 2, 3, 4, 5);  // This will print only the type of value// being converted i.e. 'Array'echo strval ( $arr );  ?>

参考:http://php.net/manual/en/func...

更多PHP开发相干内容请参考:lsbin - IT开发技术:https://www.lsbin.com/

PHP相干内容举荐:

  • PHP中将PDF文档转换为预览图像:https://www.lsbin.com/2545.html
  • PHP数组操作:https://www.lsbin.com/2811.html
  • PHP在浏览器关上PDF文件:https://www.lsbin.com/523.html