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

is_iterable

验证变量的内容是否为可迭代值
名称:is_iterable
分类:变量处理
所属语言:php
一句话介绍:检查变量的内容是否是可迭代的值。

定义和用法

is_iterable() 函数检查变量的内容是否是可迭代的值。

如果变量是可迭代的,则该函数返回 true (1),否则返回 false/无返回值。

实例

检查变量的内容是否是可迭代的值:

<?php
$a = "Hello";
echo "a is " . is_iterable($a) . "<br>";

$b = array("red", "green", "blue");
echo "b is " . is_iterable($b) . "<br>";

$c = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "c is " . is_iterable($c) . "<br>";

$d = [1, 2, 3];
echo "d is " . is_iterable($d) . "<br>";
?>

亲自试一试

语法

is_iterable(variable);
参数 描述
variable 必需。指定要检查的变量。
同类函数
  • 检测变量是否是一个标量  is_scalar

    is_scalar

    检测变量是否是一个标量
  • 检测参数是否为合法的可调用结构  is_callable

    is_callable

    检测参数是否为合法的可调用结构
  • 获取变量的布尔值  boolval

    boolval

    获取变量的布尔值
  • 检测变量是否已设置并且非 null  isset

    isset

    检测变量是否已设置并且非null
  • 获取变量的类型(可以为数组、字符串、匿名类和对象返回更有用的输出信息)  get_debug_type

    get_debug_type

    获取变量的类型(可以为数组、字符串、匿名
  • 检测变量是否是整数  is_int

    is_int

    检测变量是否是整数
  • 返回给定资源的整数标识符  get_resource_id

    get_resource_id

    返回给定资源的整数标识符
  • is_int 的别名  is_integer

    is_integer

    is_int的别名