站长资讯网
最全最丰富的资讯网站

PHP如何使用strval()函数?

本篇文章给大家介绍一下PHP使用strval()函数的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

PHP如何使用strval()函数?

PHP如何使用strval()函数?

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

语法:

strval( $variable )

参数:此函数接受单个参数$变量。此参数表示我们要转换为字符串的值

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

下面的程序说明了strval()函数。

程序1:

<?php    $var_name = 32.360;    // prints the value of above variable  // as a string echo 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 string echo 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 );    ?>

推荐学习:php视频教程

赞(0)
分享到: 更多 (0)

网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号