is_resource
检测变量是否为资源类型
is_resource()
函数用于检查变量是否为资源类型。
注意:如果资源已关闭,is_resource()
函数将返回 FALSE
。
如果变量是资源,则该函数返回 true
(1),否则返回 false
/无返回值。
检查变量是否是资源:
<?php $file = fopen("test.txt","r"); if (is_resource($file)) { echo "File is open"; } else { echo "Error open file"; } ?>
亲自试一试
is_resource(variable);
参数 | 描述 |
---|---|
variable | 必需。指定要检查的变量。 |