PHP is_resource() Function

PHP is_scalar() Function
PHP is_real() Function

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);
ParameterDescription
variableRequired. Specifies the variable to check
PHP IS_RESOURCE() method

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";
}
?>
PHP is_scalar() Function
PHP is_real() Function
en English
X
Scroll to Top