当前位置: 首页> 函数类别大全> settype

settype

设置变量的类型
名称:settype
分类:变量处理
所属语言:php
一句话介绍:将变量转换为特定类型。

定义和用法

settype() 函数将变量转换为特定类型。

实例

将变量转换为特定类型:

<?php
$a = "32"; // string
settype($a, "integer"); // $a 现在是整数

$b = 32; // integer
settype($b, "string"); // $b 现在是字符串 

$c = true; // boolean
settype($c, "integer"); // $c 现在是整数 (1)
?>

亲自试一试

语法

settype(variable, type);
参数 描述
variable 必需。指定要转换的变量。
type

必需的。指定要将变量转换为的类型。可能的类型有:

  • boolean
  • bool
  • integer
  • int
  • float
  • double
  • string
  • array
  • object
  • null
同类函数
  • 检测参数是否为合法的可调用结构  is_callable

    is_callable

    检测参数是否为合法的可调用结构
  • 验证变量的内容是否为可计数值  is_countable

    is_countable

    验证变量的内容是否为可计数值
  • 检查一个变量是否为空  empty

    empty

    检查一个变量是否为空
  • 获取变量的整数值  intval

    intval

    获取变量的整数值
  • 检测变量是否是一个标量  is_scalar

    is_scalar

    检测变量是否是一个标量
  • 输出或返回一个变量的字符串表示  var_export

    var_export

    输出或返回一个变量的字符串表示
  • 检测变量是否为数字或数字字符串  is_numeric

    is_numeric

    检测变量是否为数字或数字字符串
  • 检测变量是否为 null  is_null

    is_null

    检测变量是否为null
热门文章