PHP is_iterable() 函数
实例
检查变量的内容是否为可迭代值:
<?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>";
?>
亲自试一试 »
$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() 函数检查变量的内容是否为可迭代值。
如果变量是可迭代的,则此函数返回 true (1),否则返回 false/nothing。
语法
is_iterable(variable);
参数值
参数 | 描述 |
---|---|
variable | 必需。指定要检查的变量 |
技术细节
返回值: | 如果 变量 是可迭代的,则为 TRUE,否则为 FALSE |
---|---|
返回类型: | Boolean |
PHP 版本: | 7.1+ |