w3resource

PHP: is_resource() function

Description

The is_resource () function is used to find whether a variable is a resource or not.

Version:

(PHP 4 and above)

Syntax:

is_resource(var_name)

Parameter:

Name Description Required /
Optional
Type
var_name The variable being checked Required Mixed*

*Mixed: Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Return value:

TRUE if var is a resource, FALSE otherwise.

Value Type: Boolean.

Example :

<?php
$fh = fopen('demo.txt','r');
if (is_resource($fh)) 
{
echo "File is open successfully......";
}
else
echo "wrong way to open a file";
?>

Output:

File is open successfully......

View the example in the browser

See also

PHP Function Reference

Previous: is_real
Next: is_scalar



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/is_resource.php