PHP 提供了多种函数进行数据转换,包括:整数转换:intval()、floatval()、abs()字符串转换:strval()、strlen()、substr()、strtoupper()、strtolower()、trim()、explode()、implode()数组转换:array_sum()、array_count_values()、array_reverse()、array_intersect()、array_diff()日期和时间转换:strtotime()、date()、mkt

PHP 数据转换
PHP 提供了多种函数来转换数据类型:
整型
-
intval():将值转换为整数 -
floatval():将值转换为浮点数 -
abs():取得绝对值 -
round():四舍五入 -
floor():向下舍入 -
ceil():向上舍入
字符串
立即学习“PHP免费学习笔记(深入)”;
-
strval():将值转换为字符串 -
strlen():取得字符串长度 -
substr():取得子字符串 -
strtoupper():转换为大写 -
strtolower():转换为小写 -
trim():修剪字符串 -
explode():分割字符串 -
implode():连接数组为字符串
数组
-
array_sum():求和 -
array_count_values():统计每个值出现的次数 -
array_reverse():反转数组 -
array_intersect():取两个数组的交集 -
array_diff():取两个数组的差集
日期和时间
-
strtotime():将日期时间字符串转换为时间戳 -
date():格式化时间戳 -
mktime():创建时间戳
其他
-
boolval():将值转换为布尔值 -
json_encode():将值编码为 JSON 字符串 -
json_decode():将 JSON 字符串解码为值











