In this article, you will learn how to check if a variable is resource variable or not. The PHP is_resource() function checks whether a variable is a resource or not.
Note: The is_resource() function will return FALSE if the resource has been closed. This function returns true (1) if the variable is a resource, otherwise it returns false/nothing.
what is the syntax of the IS_RESOURCE() function in php?
is_resource(variable);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
examples of the IS_RESOURCE() function
Example 1. In this example, we check whether a variable is a resource or not.
<?php
$file = fopen("test.txt","r");
if (is_resource($file)) {
echo "File is open";
} else {
echo "Error open file";
}
?>