php中数字转字符串的函数:1、strval(),语法格式“strval (数字变量)”,可获取并返回变量的字符串值;2、settype(),语法格式“settype(数字变量,'string')”,可将变量设置为“string”类型。
本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑
php中数字转字符串
方法1:使用strval()函数
<?php $int_str= 123.52; var_dump($int_str); $str = strval($int_str); var_dump($str); ?>输出:
float 123.52 string '123.52' (length=6)说明:
strval()函数是用于数值转字符串的转换函数,可以获取并返回变量的字符串值。
strval()函数转换数据类型,但不会影响原变量的类型。
方法2:settype()函数
<?php header('content-type:text/html;charset=utf-8'); $old = 500; echo "原数据类型" . gettype($old), '<br>'; $current = gettype(settype($old, 'string')); echo "现数据类型" . gettype($current), '<hr>'; $old = 500.25; echo "原数据类型" . gettype($old), '<br>'; $current = gettype(settype($old, 'string')); echo "现数据类型" . gettype($current), '<hr>'; ?>输出:
说明:settype() 函数用于设置变量的类型。语法如下:
settype ( $var , $type )将变量 var 的类型设置成 type。
参数 描述var 要转换的变量。
type
type 的可能值为:
“boolean” (或为“bool”,从 PHP 4.2.0 起) “integer” (或为“int”,从 PHP 4.2.0 起) “float” (只在 PHP 4.2.0 之后可以使用,对于旧版本中使用的“double”现已停用) "string" "array" "object" “null” (从 PHP 4.2.0 起)settype()函数会影响原变量的类型。
推荐学习:《PHP视频教程》
以上就是php中数字转字符串的函数有哪些的详细内容!
查看更多关于php中数字转字符串的函数有哪些的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did51940
php中数字转字符串的函数有哪些
阅读:47次